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.

Custom loadLanguageAsync function

See original GitHub issue

What problem does this feature solve?

Currently there is an option to lazy load locale messages that are spread over separate files in a specified directory. This is a nice feature but it is very specific. It uses internal loadLanguageAsync function. I would prefer to have more control over how the messages are loaded. If I can provide custom lazy load function to be used in place of loadLanguageAsync I would be able, for example, to fetch the messages from an API or whatever. The function should take care of caching on its own.

What does the proposed changes look like?

One way to go might be to allow the lazy option in nuxt.config.js to accept both Boolean and Function:

i18n: {

    lazy: ( ctx, locale) => ctx.$http.$get(`locales/${locale}`)

}

This approach has the drawback that the function will not be transpiled during build. Therefore, probably registering it via a plugin would be the best. Maybe something like:

export default function({app, installI18n}){

    installI18n(
        // pass context & inject as they will probably be needed
        ...arguments, 

        // pass additional options to be merged with nuxt.config.i18n
        {
            lazy: ( ctx, locale) => ctx.$http.$get(`locales/${locale}`)
        }
    )
}

But event without transpiling, simply having this option would be great!

Hope you find this feature convenient.

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

5reactions
desislavsdcommented, Jul 29, 2020

I believe this is already possible since the locale file can be a script that exports a function and it’s also passed context and locale.

The only weird thing about it right now is that if you have multiple locales you would have to assign the same file to all of them configuration.

This is exactly what I did when opened the issue 😄. But it feels bad. This functionality is needed as I often need to provide the clients with the ability to update phrases real time in their admin panel. I cannot afford to rebuild the project each time. Also I believe, the functionality can be achieved with a minor tweak in a single line of code.

0reactions
stale[bot]commented, Nov 1, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom loadLanguageAsync function · Issue #581 - GitHub
What problem does this feature solve? Currently there is an option to lazy load locale messages that are spread over separate files in...
Read more >
Lazy loading translations | Vue I18n
The loadLanguageAsync function is what we will actually use to change the languages. Loading the new files is done via the import function, ......
Read more >
vue-i18n lazy loading is loading all locales - Stack Overflow
I would expect it to load the files only when called, but when the page is refreshed, it will download all files that...
Read more >
The Answers to All Your Questions About Gridsome Localization
We have a seti18nLanguage() method that will take lang as a parameter and simply set that language. loadLanguageAsync() does three things:.
Read more >
resolved issue of json file for loadLanguageAsync removed ...
resolved issue of json file for loadLanguageAsync removed gitart-vue-dialog and added ... axios.interceptors.request.use(function (config) {.
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