-
Notifications
You must be signed in to change notification settings - Fork 5.1k
i18n next-intl
#14906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18n next-intl
#14906
Conversation
✅ Deploy Preview for ethereumorg ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -59,7 +61,6 @@ module.exports = (phase, { defaultConfig }) => { | |||
|
|||
return config | |||
}, | |||
i18n, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified the Link
component to handle this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/components/Translation.tsx
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important change. Adaptation of the Translation
component. It changes a bit the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important change.
if (isInternalPdf) { | ||
href = getRelativePath(asPath, href) | ||
if (isInternalFile && !href.startsWith("/")) { | ||
href = "/" + getRelativePath(pathname, href) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert relative paths into absolute paths
@@ -112,15 +113,11 @@ export const BaseLink = forwardRef<HTMLAnchorElement, LinkProps>(function Link( | |||
) | |||
} | |||
|
|||
if (isInternalPdf) { | |||
if (isInternalFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uses this strat for all files, not just pdfs. This adds support for opening md images and assets in /assets.
src/hooks/useTranslation.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created this abstraction to add backwards compatibility with the args that we could handle, making the transition easier.
src/i18n/loadNamespaces.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
src/i18n/request.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be ignored. Not important at this point since this is used for app router pages.
src/middleware.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to handle the default locale scenario.
@@ -96,7 +98,16 @@ const H3 = (props: ChildOnlyProp) => ( | |||
<h3 className="mb-0 mt-10 leading-xs" {...props} /> | |||
) | |||
|
|||
export const getStaticProps = (async ({ locale }) => { | |||
export async function getStaticPaths() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a missing translation, output just the key without the namespace.
Description
This PR implements
next-intl
replacing the previous i18n librarynext-i18next
. This is the initial step towards the use of the app router.Changes for this transition
i18n
mechanism from nextjs. This is all handled bynext-intl
and by the page components usinggetStaticPaths
. The load of namespaces logic is now in our control, created aloadNamespaces
function.[locale]
next-intl
. These areuseTranslation
,useRouter
,usePathname
,useLocale
BUILD_LOCALES
toNEXT_PUBLIC_BUILD_LOCALES
since we need to use it to get all locales used in client components.Link
component to use the i18n navigation componentsThings to test
Preview link
https://deploy-preview-14906--ethereumorg.netlify.app/