Replies: 1 comment 5 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.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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, eitherar
oren
, and I need to dynamically setnext-i18next
default 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.lang
attribute in the HTMLdocumentElement
, I set theNEXT_LOCALE
cookie andContent-Language
header to the tenant locale.serverSideTranslations
to fetch the correct translations._document.tsx
, I read the locale fromNEXT_LOCALE
to set thelang
anddir
attributes 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
lang
attribute 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:
defaultLocale
in both i18next and Next.js based on user selection?NEXT_LOCALE
cookie and accessing it in_document.tsx
a correct approach for setting the rightlang
anddir
? Are there better alternatives?lang
attribute 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