@nuxtjs/i18n Locales在刷新后更改
我有一个应用程序,试图将语言管理放置,但我面临困难。 我使用的是@nuxtjs/i18n
的最新版本。当我更改语言时,我的URL改变,标签会改变,一切都很好。但是,当我刷新页面时,系统会恢复到旧语言。
这是我的conf:
[
'@nuxtjs/i18n',
{
locales,
defaultLocale,
lazy: true,
langDir: 'locales/',
vueI18n: {
fallbackLocale: defaultLocale,
},
},
],
['~/.build/merge-and-compare-locales.js', { defaultLocale }],
export const locales = [
{
code: 'en',
file: 'en.json',
},
{
code: 'fr',
file: 'fr.json',
},
]
export const defaultLocale = 'fr'
在刷新之前,我还需要做些什么才能保持语言?
我指定使用此方法来更改语言:
changeLocale(code: string) {
this.$i18n.setLocale(code)
},
本地效果很好。另一方面,在任何其他环境中,刷新都可以返回默认语言
I have an application where I try to put the language management but I face a difficulty.
I'm on the latest version of @nuxtjs/i18n
. When I change language, my URl changes, my labels change, everything is fine. When I refresh my page, however, the system reverts to the old language.
Here is my conf:
[
'@nuxtjs/i18n',
{
locales,
defaultLocale,
lazy: true,
langDir: 'locales/',
vueI18n: {
fallbackLocale: defaultLocale,
},
},
],
['~/.build/merge-and-compare-locales.js', { defaultLocale }],
export const locales = [
{
code: 'en',
file: 'en.json',
},
{
code: 'fr',
file: 'fr.json',
},
]
export const defaultLocale = 'fr'
What more do I need to do to make it keep the language before refresh?
I specify that I use this method to change the language:
changeLocale(code: string) {
this.$i18n.setLocale(code)
},
Locally it works fine. On the other hand on any other environment it does not work, the refresh makes return to the default language
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有同样的问题,它来自SSR ...
在您的商店/索引内部,您应该具有NSI(NUXT服务器init)功能
这样的东西。
i have same problem and it's come from ssr...
inside your store/index you should have a nsi (nuxt server init) function
something like this.