I am currently working on an application where I am implementing language management, but I have encountered a difficulty. I am using the latest version of @nuxtjs/i18n
. Changing the language successfully updates the URL and labels, yet upon refreshing the page, it reverts to the old language.
Below is my configuration:
[
'@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 steps can I take to ensure that the selected language persists even after a page refresh?
Please note that I am using the following method to change the language:
changeLocale(code: string) {
this.$i18n.setLocale(code)
},
The language change works perfectly locally, but fails on other environments where a refresh causes it to revert back to the default language.