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

Accept-Language (i18n) header not evaluated when directly accessing sub-routes #21632

Closed
mleimer opened this issue Jan 28, 2021 · 3 comments
Closed
Labels
bug Issue was opened via the bug report template.

Comments

@mleimer
Copy link

mleimer commented Jan 28, 2021

What version of Next.js are you using?

10.0.5

What version of Node.js are you using?

14.15.1

What browser are you using?

Chrome
Version 88.0.4324.104 (Official Build) (64-bit)

What operating system are you using?

Windows

How are you deploying your application?

next build & next start

Describe the Bug

Accept-Language headers of browser are not (correctly) evaluated when directly accessing a sub-page through a deep-link or alike.

Expected Behavior

Accept-Language headers of browser should be evaluated upon first access to the Next.JS application independently of the entry point (root/index or any other sub page)

Given

  • Request-Header containing Accept-Language: en,de-CH;q=0.9,de-DE;q=0.8,de;q=0.7,en-US;q=0.6
  • next.config.js being
module.exports = () => {
  return {
    i18n: {
      locales: ['de', 'en'],
      defaultLocale: 'de',
    },
  };
};

When

Then

  • should set locale within useRouter() as 'en'

To Reproduce

Use example from tutorial:
npx create-next-app nextjs-blog --use-npm --example "https://github.com/vercel/next-learn-starter/tree/master/basics-final"

Remove external data-fetching calls.

Add next.config.js with the following configuration:

module.exports = () => {
  return {
    i18n: {
      locales: ['de', 'en'],
      defaultLocale: 'de',
    },
  };
};

Print locale on different pages using

const {locale} = useRouter();
console.log(locale);

1.) Deploy above application
2.) Open http://localhost:3000/posts/ssg-ssr (or any other sub-page)
3.) locale within useRouter() should be 'en', but is 'de'

Probably a fourth case of #20488

@mleimer mleimer added the bug Issue was opened via the bug report template. label Jan 28, 2021
@mleimer
Copy link
Author

mleimer commented Jan 28, 2021

I just identified that this is probably rather a feature request, as the docs limit said behavior to the root page.

When a user visits the application root (generally /), Next.js will try to automatically detect which locale the user prefers based on the Accept-Language header and the current domain.

@mleimer mleimer closed this as completed Jan 28, 2021
@romaincointepas
Copy link

I've opened a feature request at #22361.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants