i18n next-intl#14906
Conversation
✅ Deploy Preview for ethereumorg ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
|
||
| return config | ||
| }, | ||
| i18n, |
There was a problem hiding this comment.
Important change. This is not supported in the app router, removing now and building the pages using getStaticPaths
| href={imgSrc} | ||
| onClick={matomoHandler} | ||
| target="_blank" | ||
| locale={false} |
There was a problem hiding this comment.
Modified the Link component to handle this case.
There was a problem hiding this comment.
Im leaving this for this transition. Should be fixed once we moved to the app router.
For context, the main purpose of this was to remove the query params from the url once the page loads.
There was a problem hiding this comment.
Important change. Adaptation of the Translation component. It changes a bit the API.
| if (isInternalPdf) { | ||
| href = getRelativePath(asPath, href) | ||
| if (isInternalFile && !href.startsWith("/")) { | ||
| href = "/" + getRelativePath(pathname, href) |
There was a problem hiding this comment.
Convert relative paths into absolute paths
| } | ||
|
|
||
| if (isInternalPdf) { | ||
| if (isInternalFile) { |
There was a problem hiding this comment.
Uses this strat for all files, not just pdfs. This adds support for opening md images and assets in /assets.
There was a problem hiding this comment.
Created this abstraction to add backwards compatibility with the args that we could handle, making the transition easier.
There was a problem hiding this comment.
Loading the namespace is not handled by the i18n library.
This logic tries to mimic what we were doing before:
- tries to load the namespace for the locale + the default locale, and merges both to default to english in missing translations
- if the namespace doesn't exist, it loads the default one
There was a problem hiding this comment.
Can be ignored. Not important at this point since this is used for app router pages.
There was a problem hiding this comment.
We don't need to handle the default locale scenario.
| ) | ||
|
|
||
| export const getStaticProps = (async ({ locale }) => { | ||
| export async function getStaticPaths() { |
There was a problem hiding this comment.
All pages now needs to export the expected paths
| } | ||
|
|
||
| export const getStaticProps = (async ({ params }) => { | ||
| const { locale = DEFAULT_LOCALE } = params || {} |
There was a problem hiding this comment.
The locale is now passed as a param as its not part of the context anymore.
| // Suppress errors by default, enable if needed to debug | ||
| // console.error(error) |
There was a problem hiding this comment.
Once we fix all our missing translations, we could enable this and let the build failed. For now, we are suppressing them as we are doing currently.
| }} | ||
| getMessageFallback={({ key }) => { | ||
| const keyOnly = key.split(".").pop() | ||
| return keyOnly || key |
There was a problem hiding this comment.
If a missing translation, output just the key without the namespace.

Description
This PR implements
next-intlreplacing the previous i18n librarynext-i18next. This is the initial step towards the use of the app router.Changes for this transition
i18nmechanism from nextjs. This is all handled bynext-intland by the page components usinggetStaticPaths. The load of namespaces logic is now in our control, created aloadNamespacesfunction.[locale]next-intl. These areuseTranslation,useRouter,usePathname,useLocaleBUILD_LOCALEStoNEXT_PUBLIC_BUILD_LOCALESsince we need to use it to get all locales used in client components.Linkcomponent to use the i18n navigation componentsThings to test
Preview link
https://deploy-preview-14906--ethereumorg.netlify.app/