我有一个简单的项目,应该与英语和荷兰语(默认)的工作。我复制了原始示例中的所有内容,但不知何故,它并没有像预期的那样工作。
即使我有browserLanguageDetection: false,它也迫使我使用/en端点。
我想在/上显示NL文本,但目前无法显示。
你能检查一下沙箱,告诉我这里出了什么问题吗?
https://codesandbox.io/s/pensive-galileo-zifjm?file=/pages/index.js
发布于 2020-11-14 06:59:21
重要的是要知道,在Next.js中,第一次加载总是在服务器端完成。在i18n.js中,您定义了browserLanguageDetection: false,但没有定义serverLanguageDetection: false,这就是为什么您总是被重定向到/en
在索引页中,将此行export default withTranslation('common')(IndexPage);替换为以下export default withTranslation(['common'])(IndexPage);,以避免此warning
发布于 2021-05-03 20:03:42
文档中有解决方案。这就是:https://nextjs.org/docs/advanced-features/i18n-routing
看起来不错。
i18n: {
defaultLocale: 'en',
locales: ['en'],
localeDetection: false, // Important!
domains: [
{
domain: 'example.com', // <-
defaultLocale: 'en' // This locale will be appeared at the exact above domain.
},
{
// 2nd locale goes here in the same way.
}
]
}我希望这会有帮助。
https://stackoverflow.com/questions/64822738
复制相似问题