Custom loadLanguageAsync function
See original GitHub issueWhat 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:
- Created 4 years ago
- Comments:10
Top GitHub Comments
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.
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.