我想根据域名选择网站的默认语言,例如:
www.test.fr --> 默认语言为法语
www.test.de --> 默认语言为德语
...
那我该怎么做?
应用使用next.js开发,后端使用symfony 2.6
答案 0 :(得分:4)
您需要将 i18n
配置添加到您的 next.config.js
文件中:
// next.config.js
module.exports = {
i18n: {
// These are all the locales you want to support in
// your application
locales: ['en-US', 'fr', 'nl-NL'],
// This is the default locale you want to be used when visiting
// a non-locale prefixed path e.g. `/hello`
defaultLocale: 'en-US',
// This is a list of locale domains and the default locale they
// should handle (these are only required when setting up domain routing)
// Note: subdomains must be included in the domain value to be matched e.g. "fr.example.com".
domains: [
{
domain: 'example.com',
defaultLocale: 'en-US',
},
{
domain: 'example.nl',
defaultLocale: 'nl-NL',
},
{
domain: 'example.fr',
defaultLocale: 'fr',
},
],
},
}
docs 中的更多信息和示例。