question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lazy loading for locales list

See original GitHub issue

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.

<div align="right">This feature request is available on Nuxt community (#c217)</div>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:12

github_iconTop GitHub Comments

2reactions
cannapcommented, Jun 26, 2019

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 😕

1reaction
fahamidevcommented, Sep 15, 2019

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lazy loading for locales list · Issue #256 · nuxt-modules/i18n
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...
Read more >
How to Load i18n Locales Asynchronously in Vue 3 + Vite
Learn how to load Vue I18n locales lazily in your multi-language Vue 3 + Vite ... Then navigate to the project root directory,...
Read more >
Lazy load locales for nuxt-i18n - vue.js - Stack Overflow
The solution was simple. Nuxt allows you to export an async function as options so I can get the data and next assign...
Read more >
Lazy loading translations | Vue I18n
Lazy loading or asynchronously loading the translation files is really easy when using Webpack. The lang folder is where all of our translation ......
Read more >
Lazy Load and Encapsulate i18n Files in Angular with Transloco
In order to load the feature's translations, we can define the TRANSLOCO_SCOPE provider and pass an inline loader that leverages Webpack's import function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found