Replies: 1 comment 6 replies
-
|
currently afk... not read all your text so carefully, but Next.js is doing its own language detection, if I remember correctly there should be an option to disable that in the nextjs config... vercel/next.js#18617 |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I’m currently working on a multi-tenant aoo where the user has the option to select the default locale from a list of available locales (
ar, en). for now, the app supports only one language at a time, eitheraroren, and I need to dynamically setnext-i18nextdefault locale to the one that the user has selected.Here's how I've implemented it so far:
getServerSideProps, I am fetching the tenant settings and getting the tenant locale.langattribute in the HTMLdocumentElement, I set theNEXT_LOCALEcookie andContent-Languageheader to the tenant locale.serverSideTranslationsto fetch the correct translations._document.tsx, I read the locale fromNEXT_LOCALEto set thelanganddirattributes dynamically based on the user's chosen locale.here is how my code looks like:
index.tsx_document.tsx:However, I’ve noticed that on the first page render, while the
langattribute of the document element is correctly set, it reverts back to the default locale from my configuration whenever the route changes.my questions and issues are:
defaultLocalein both i18next and Next.js based on user selection?NEXT_LOCALEcookie and accessing it in_document.tsxa correct approach for setting the rightlanganddir? Are there better alternatives?langattribute to the default locale in the config on each route change, and and how can I prevent this?useRouter, it returns the default locale, it does not change until I add the language prefix to the URL (e.g.,/en/path). How can I change the locale without changing the URL?any help or guidance would be greatly appreciated. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions