You can use the Lazy-load translations in nuxt-i18n
First, create a structure for languages similar to this:
nuxt-project/
├── lang/
│ ├── en-US.js
│ ├── es-ES.js
│ ├── fr-FR.js
├── nuxt.config.js
Then set the nuxt.config
configuration. Note that you need to set lazy: true
and the langDir
// nuxt.config.js
['nuxt-i18n', {
locales: [
{
code: 'en',
file: 'en-US.js'
},
{
code: 'es',
file: 'es-ES.js'
},
{
code: 'fr',
file: 'fr-FR.js'
}
],
lazy: true,
langDir: 'lang/'
}]
Then, inside the lang files you can call your API and return the json with the translation messages, like this:
// lang/[lang].js
export default (context) => {
return new Promise(function (resolve) {
//Call your API and resolve the content here
resolve({
//The JSON return from your API
})
});
}
You can find more details in the documentation