Answer the question
In order to leave comments, you need to log in
How to change language in i18n in Nuxt app?
I have an application in Nuxt JS
I want to switch the language of the text using the i18n plugin
How to switch the language correctly?
Here's what I did, but it doesn't work:
Created files in the project for languages:
/lang/en.js
/lang/ru.js
Added config for i18n in nuxt.config.sj file:
['nuxt-i18n', {
locales: [
{
code: 'en',
file: 'en.js'
},
{
code: 'ru',
file: 'ru.js'
},
],
lazy: true,
langDir: 'lang/',
defaultLocale: 'en'
}]
export default {
home: 'Home'
}
<NuxtLink to="/" @click.native="closeNav">{{home}}</NuxtLink>
computed: {
home() {
return this.$t('home');
}
},
methods: {
changeLanguageToRU() {
this.$i18n.locale = 'ru';
}
changeLanguageToENG() {
this.$i18n.locale = 'en';
}
}
Answer the question
In order to leave comments, you need to log in
I did not find in the documentation about the method that changes languages
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question