vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.19k stars 27.02k forks source link

i18n domains does not match subdomaints #56926

Open pavelglac opened 1 year ago

pavelglac commented 1 year ago

Link to the code that reproduces this issue

https://github.com/pavelglac/next-i18n-domains

To Reproduce

next.config.js:

  i18n: {
    locales: ['en', 'cs'],
    defaultLocale: 'en',
    localeDetection: false,
    domains: [
      {
        domain: 'example.com',
        defaultLocale: 'en',
      },
      {
        domain: 'example.cz',
        defaultLocale: 'cs',
      },
    ],
  },
  1. www.example.cz will use en locale

Current vs. Expected behavior

current

www.example.cz use en locale

expected

www.example.cz should use cs locale according docs where provided examples according the table bellow should also match www variant.

Verify canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
Binaries:
  Node: 16.18.1
  npm: 9.1.2
  Yarn: 3.5.0
  pnpm: N/A
Relevant Packages:
  next: 13.5.6-canary.1
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.0.4
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Internationalization (i18n)

Additional context

No response

geweidong commented 1 year ago

Do you have finished this problem? I have the same problem too.Very embarrsed to looking no anwers....

pavelglac commented 1 year ago

The only way how to fix it is in middleware. You can inspire in https://nextjs.org/docs/pages/building-your-application/routing/internationalization#prefixing-the-default-locale.