i18n
i18n copied to clipboard
Lazy loading for locales list
What problem does this feature solve?
In some cases, there's a need for a dynamic locales list (i.e. localizations created by editor on CMS). Currently, locales
only allows a static array.
What does the proposed changes look like?
To allow dynamic locales listing, locales
should allow functions as well, including those returning a Promise
.
What status for this request?
i need this also or is there a way to manipulate via module
export default function lang () {
/**
locales: [
{
code: 'en',
iso: 'en-US',
name: 'English',
file: 'en.json'
},
{
code: 'de',
iso: 'de-DE',
name: 'Deutsch',
file: 'de.json'
}
],
*/
this.options.i18n.locales = [
{
code: 'en',
iso: 'en-US',
name: 'English',
file: 'en.json'
},
{
code: 'de',
iso: 'de-DE',
name: 'Deutsch',
file: 'de.json'
}
]
}
i tried but i it seems not working
found a solution
nuxt.config.js defaults is just a normal nuxt config obj
export default async () => {
const url = `${process.env.BASE_URL}/translation/languages`
const { data: response } = await axios.get(url)
const locales = response.data.map(lang => {
return {
...lang,
file: `${lang.code}.json`
}
})
defaults.i18n.locales = locales
return defaults
}
//e i forgot that every languages needs a file which returns content or a promise :/
This is also necessary for pages. I am using Wordpress as a headless CMS and I made an endpoint that returns the sites structure. This would help me add and remove pages from CMS.
Currently I can work with the solution provided by cannap, but when the pages and locales options would allow functions this plugin would be perfect ❤️.
@cannap Thank you very mutch to share your information about this topic and also your answer. Really i think this is my answer too, But i don't know where can i use this in my code, i mean which part of my code i have to put it?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This is taking the locales on the build time. Is it also possible to load the locales on runtime? Eg, when the site is loaded?
export default async () => { const url = `${process.env.BASE_URL}/translation/languages` const { data: response } = await axios.get(url) const locales = response.data.map(lang => { return { ...lang, file: `${lang.code}.json` } }) defaults.i18n.locales = locales return defaults }
No, the module generates routes based on specified locales and it can only do that at build time.