2

How do you approach multisite and multingual site configuration without locale within URL?

The problem I am facing is that i18n configuration requires to define 'defaultLocale'. I would like to support the following case.

For an instance www.turkishwebsite.com/ => should respond with tr-tr (default language for the site is tr-tr) www.turkishwebsite.com/en-gb should respond with en-gb

www.chinesewebsite.com/ should respond with en-gb (default language for the site is en-gb) www.chinesewebsite.com/zh-hk should respond with zh-hk

As i18n config requires to define default locale, my context.locale is en-gb for the following visit www.turkishwebsite.com/, which is improper in my case. Is it possible to handle it without defining default locale for each domain separately? (it has some limitation in number of domains and is unpractical if deployment is made for different environments)

without bolded config below i18n: { locales: ['en', 'fr'], defaultLocale: 'en', localeDetection: false, domains: [ { domain: 'domain1.com', defaultLocale: 'en' }, { domain: 'domain2.fr', defaultLocale: 'fr' }, { domain: 'domain2.com', defaultLocale: 'fr' } ] },

1 Answer 1

3

You can use 'default' as the default language in the i18n section of the next-config.js. This will ensure you have a unique default language for each domain.

So, for each site node in the Sitecore instance if you want to have multiple domains with default language set for the domains, you can use the following code in the i18n section:

 { 
    locales: ['default', 'en', 'fr'], 
    defaultLocale: 'default', 
    localeDetection: false, 
    domains: [ 
        { 
            domain: 'domain1.com', 
            defaultLocale: 'en' 
        }, 
        { 
            domain: 'domain2.fr', 
            defaultLocale: 'fr' 
        }
            ] 
},

You can refer this documentation:

https://nextjs.org/docs/pages/building-your-application/routing/internationalization#prefixing-the-default-locale

2
  • Thanks, this is what I did - defined defaultLocale: 'default', additionally I had to add middleware with the following logic if locale == 'default' { req.nextUrl.locale = '{defLanguage}'}. As far as I remember to i18n config in next.config.js I had to also add localeDetection: false. Commented Apr 24 at 6:10
  • Yes setting "localeDetection: false" is a necessary step here. Commented Apr 25 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.