Next.js Discord

Discord Forum

App router Internationalization

Unanswered
Cane Corso posted this in #help-forum
Open in Discord
Cane CorsoOP
Hey, i want to add internationalization/translations to my website, on the latest version of next.js using the app directory.
but I don't want the language to be set by a url prefix (the [locale] url param), i want it to be set on the cookies/localStorage, i assume there is some package or way to do that.
is there a known package or a preferred way of doing that?

2 Replies

American Crow
next-intl
https://next-intl-docs.vercel.app/docs/routing/middleware#strategies

Locale detection

The locale is detected based on these priorities:

   1. A locale prefix is present in the pathname (e.g. /en/about)
   2. A cookie is present that contains a previously detected locale
   3. A locale can be matched based on the accept-language header

   4. As a last resort, the defaultLocale is used


You'll have to use a [locale] folder in your project though. thats how i18n works with this
You can turn off the locale prefix as well if that is your goal:
https://next-intl-docs.vercel.app/docs/routing/middleware#locale-prefix-never