Select 域名默认语言
Select the default language according the domain name
我想select根据域设置网站的默认语言,例如:
www.test.fr --> 默认语言是法语
www.test.de --> 默认语言是德语
...
那我该怎么做呢?
应用程序是使用 next.js 开发的,后端是 symfony 2.6
您需要将 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 中的更多信息和示例。
我想select根据域设置网站的默认语言,例如:
www.test.fr --> 默认语言是法语
www.test.de --> 默认语言是德语
...
那我该怎么做呢?
应用程序是使用 next.js 开发的,后端是 symfony 2.6
您需要将 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 中的更多信息和示例。