TT
TT
NNuxt
Created by TT on 4/17/2024 in #❓・help
Reserved Keywords in i18n ?
Alright I'll refacto the logic
9 replies
NNuxt
Created by TT on 4/17/2024 in #❓・help
Reserved Keywords in i18n ?
"@nuxtjs/i18n": "^7.2.2"
"@nuxtjs/i18n": "^7.2.2"
I will try refactoring the logic I think ! Thanks
9 replies
NNuxt
Created by TT on 4/17/2024 in #❓・help
Reserved Keywords in i18n ?
<template>
<Select v-model="$root.$i18n.locale" @change="changeLocaleRoute" variant="primary">
<option v-for="locale in $i18n.locales" :key="locale.iso" :value="locale.code">{{ locale.name }}</option>
</Select>
</template>

<script>
export default {
methods: {
changeLocaleRoute() {
const newLocale = this.$root.$i18n.locale;
this.$nextTick(() => {
let newPath = this.localePath(this.$route.fullPath, newLocale);
if (newLocale === this.$i18n.defaultLocale) {
newPath = newPath.replace(`/${newLocale}`, '');
}

this.$store.commit('setLocale', newLocale);
sessionStorage.setItem('locale', newLocale);

if (newPath !== this.$route.fullPath) {
window.location = newPath;
}
});
},

}
};
</script>
<template>
<Select v-model="$root.$i18n.locale" @change="changeLocaleRoute" variant="primary">
<option v-for="locale in $i18n.locales" :key="locale.iso" :value="locale.code">{{ locale.name }}</option>
</Select>
</template>

<script>
export default {
methods: {
changeLocaleRoute() {
const newLocale = this.$root.$i18n.locale;
this.$nextTick(() => {
let newPath = this.localePath(this.$route.fullPath, newLocale);
if (newLocale === this.$i18n.defaultLocale) {
newPath = newPath.replace(`/${newLocale}`, '');
}

this.$store.commit('setLocale', newLocale);
sessionStorage.setItem('locale', newLocale);

if (newPath !== this.$route.fullPath) {
window.location = newPath;
}
});
},

}
};
</script>
This is how I switch languages, I refresh one time my application to load the new language, when I console.log the locale its the good one. It seems like there is a conflict because of the name 'de' and 'deals' because it retrieve my content in french as well, so its the whole page that is in french (translation) + the content (I pass the variable i18n.locale), when I switch page from the bugged one, I still have my /de before my other pages, so its related to this page only. What is weird is that if I switch the languages from the /deals page, it refresh and show me well the /de/deals with the good translation and content so I guess it is not my translation file the problem.. Not sure if I understand your question ?
9 replies