Skip to content
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

Allow for a defaultLocale override #753

Closed
cipriancaba opened this issue Jan 3, 2024 · 3 comments
Closed

Allow for a defaultLocale override #753

cipriancaba opened this issue Jan 3, 2024 · 3 comments
Labels
enhancement New feature or request unconfirmed Needs triage.

Comments

@cipriancaba
Copy link

Is your feature request related to a problem? Please describe.

Currently, there is no way to override the defaultLocale, it will always be set based on the accept-language header. The following config does nothing for me, it's always the browser header that decides

const handleI18nRouting = createIntlMiddleware({
    locales: ["en", "de"],
    defaultLocale: "de",
    localePrefix: 'never',
    localeDetection: true,
  })

Describe the solution you'd like

I want to be able to override the defaultLocale by giving more priority to the defaultLocale config option

I think the order of resolving the locale should be default locale prio 3 and accept language should be prio 4

function resolveLocaleFromPrefix<Locales extends AllLocales>(

Describe alternatives you've considered

Can't seem to find a workaround, maybe I can try initially setting NEXT_LOCALE to de in the middleware

@cipriancaba cipriancaba added enhancement New feature or request unconfirmed Needs triage. labels Jan 3, 2024
@amannn
Copy link
Owner

amannn commented Jan 3, 2024

I think the order of resolving the locale should be default locale prio 3 and accept language should be prio 4

If that would be the case, the accept-language header would never be used (since a defaultLocale is mandatory).

Can you share more details on your use case?

By composing the middleware, you should have plenty of freedom. E.g. to force a particular locale for a given request, you can set the defaultLocale dynamically, limit the available locales, turn off localeDetection etc.

If you have a very special use case where the next-intl middleware doesn't help much, you can also implement your own.

@kneza23
Copy link

kneza23 commented Jan 16, 2024

So how we can override the locale for users for the first time. Since defaultLocale is not a priority, what can we do so that for example default language for all users be German but later if they want to switch to English, they can, and it would be remembered for all following visits to the application?

@amannn
Copy link
Owner

amannn commented Jan 16, 2024

You can add a redirect if a user requests the app and no NEXT_LOCALE cookie is available from a previous visit. I'll close this issue now since it seems to be a usage question.

@amannn amannn closed this as completed Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

3 participants