next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Docs: Internationalized Routing

Open federicovezzoli opened this issue 3 years ago • 1 comments

What is the improvement or update you wish to see?

Following the documentation it's not very clear how to make the intl routing works for the multi domain case. I've followed the documentation but I always get sub-path routing when next/link generates the localized routes. Is it because I'm locally? it's not clear. Is it a bug? Thanks a lot

Is there any context that might help us understand?

Here is my configuration, deploying it with on netlify.

locales: ['en-gb', 'es-es', 'de-de', 'fr-fr', 'it-it'],
    defaultLocale: 'it-it',
    domains: [
    {
      domain: 'xxx-it.netlify.app',
      defaultLocale: 'it-it'
    },
    {
      domain: 'xxx-en.netlify.app',
      defaultLocale: 'en-gb'
    },
    {
      domain: 'xxx-fr.netlify.app',
      defaultLocale: 'fr-fr'
    },
    {
      domain: 'xxx-de.netlify.app',
      defaultLocale: 'de-de'
    },
    {
      domain: 'xxx-es.netlify.app',
      defaultLocale: 'es-es'
    }
],
    localeDetection: false
  },

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/advanced-features/i18n-routing

federicovezzoli avatar Aug 03 '22 06:08 federicovezzoli

@federicovezzoli if you would like localeDetection: false in next.config.js file then try to include the locale dynamicly in the href prop of the <Link /> component, next/link docs

import Link from 'next/link'
// ...
<Link locale={locale} href={`https://xxx-${locale}.netlify.app`} >
    <a>{`xxx-${locale}.netlify.app`}</a>
</Link>

and then you need to modify locales in your next.config.js to match the domains given

locales: ['en', 'es', 'de', 'fr', 'it'],
    defaultLocale: 'it',
    domains: [
    {
      domain: 'xxx-it.netlify.app',
      defaultLocale: 'it'
    },
    {
      domain: 'xxx-en.netlify.app',
      defaultLocale: 'en'
    },
    {
      domain: 'xxx-fr.netlify.app',
      defaultLocale: 'fr'
    },
    {
      domain: 'xxx-de.netlify.app',
      defaultLocale: 'de'
    },
    {
      domain: 'xxx-es.netlify.app',
      defaultLocale: 'es'
    }
],
    localeDetection: false
  },

Or if i were you i would just enable localeDetection in next.config.js and comment out localeDetection: false, (default to true) and see how things go

Babbili avatar Aug 03 '22 08:08 Babbili

@federicovezzoli Our docs around internationalization has updated much since this issue was last reported!

  • https://nextjs.org/docs/app/building-your-application/routing/internationalization
  • https://nextjs.org/docs/pages/building-your-application/routing/internationalization

If you have any more questions around internationalization with :nextjs:, feel free to create a new bug report or a new discussion.

samcx avatar Feb 20 '24 01:02 samcx

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

github-actions[bot] avatar Mar 05 '24 12:03 github-actions[bot]