Open grzpab opened 1 year ago
Thank you for opening your first issue, one of our team members will review it as soon as it possible. ❤️🎉
Sounds like a solid plan. I was wondering what are the main differences in this approach VS the i18next blog post approach?
AFAIK we're not using the /[locale]/
prefix right?
Hello, we took a deeper dive and came up with two solutions superseding the original one. At the core of each are two principles:
next-i18next
and associated librariesBoth will work using the Pages or the App Router. Both should reduce the loading time of a page for every user. It will be faster to see the results from Solution A.
getStaticProps
function (of each page)getServerSideProps
function (of each page)getStaticProps
and getServerSideProps
functionsgetStaticProps
but we cannot use getServerSideProps
getInitialProps
of the _document
server-side componentgetServerSideProps
functionssgInit
functionalitygetServerSideProps
instantly on the server-side using:
accept-language
header<link rel="preload" fetchpriority="high" as="fetch" crossorigin="anonymous" href="..." />
with the href
pointing to the proper translation pack based on the language & calcom api version
cache: "default"
parameter:
next-i18next
and allow React to refresh all the components that contain translated phrases. getServerSideProps
) we retrieve the translation pack for the obtained language and the proper namespace correlated with the page, meaning each page will have its own namespace and some translation phrases will repeat between different pages. This translation pack is the fed into the server page component.
next-i18n
library loads them) so we would have to compile the JSON files within the app bundle and serve them from the compiled codePerhaps we should discuss if either solution is acceptable to you.
Awesome write up @grzpab Thanks for the input. IMO Solution A would be the least effort maximum impact don't you think?
Is your proposal related to a problem?
When cal.com moves to Next.js' App Router API, i18n will no longer be "natively" supported by that API, namely
.locale
,.locales
,.defaultLocale
and.domainLocales
properties of therouter
object will not be accessible.Describe the solution you'd like
I thought of an architectural change that moves the resolving of translation functions from client-side components to server-side components.
This could be achieved by the following principles:
The technical plan consists of the following steps:
i18next
module https://github.com/i18next/i18next, which contrary to the name, is agnostic of Next.js (the parent library of thenext-i18next
that Cal.com have been using),accept-language
,react-i18next
,next-i18next
libraries and associated middlewares and hooks will have to be cleaned up, eacht
andTrans
usage will have to be changed into a usage of the language object mentioned beforehand (this will be codemodable):t
fromuseLocale
from@calcom/lib/hooks/useLocale
(this is the Cal.com hook),<Trans>
fromnext-i18next
,t
fromuseTranslation
fromreact-i18next
(inAppConfiguration
).organization_banner_title
(removal can be codemoded as well).Describe alternatives you've considered
In theory, the translation could stay in the client-side components, but it has the following drawbacks:
next-i18next
library will have to be replaced anyway, as outlined here: https://github.com/i18next/next-i18next/discussions/1993#discussioncomment-4337519accept-language
header doesn't match the user settings' language, the app first fetches the former language translation pack and then the latter. The part with requests to the CDN, parsing JSON and rerendering of components (which costs time) will not occur when translating on the server-side.React.memo
) but I have yet to prove that such caching would yield noticeable benefits.Additional context
N/A
Requirement/Document
N/A