Vue-i18n: Best practices for switching locale in app?

Created on 16 Feb 2017  路  9Comments  路  Source: kazupon/vue-i18n

I am building an application where it is unsure which language the user will use, as their location will not be sufficient to predetermine their language of choice.

Is there a best practice for setting a locale with a technology such as vuex and using this locale with vue-i18n?

Thank you!

Austin

Most helpful comment

Would be nice to put an example in the documentation maybe ?

All 9 comments

Just load it.

I use $store but I would imagine you could port this quite easily.

~~~
module.exports = {

loaded: false,

set: function(lang) {
    if ( ! this.$store.settings.lang) {
        this.$store.set('lang.loaded', true);

        return;
    }

    this.$http.get(this.$env.get('APP_URL') + '/i18n/' + lang + '.json').then(function (res) {                    
        Vue.config.lang = lang;
        Vue.locale(lang, res.data);

        this.$store.set('lang.loaded', true);
    });
}

}
~~~

@websanova thanks, I will give it a try and let you know how it works. Then, I'll open up a documentation PR with my findings so that others will know ideas how to best handle this?

Any progress @awitherow ?

Nope not at all @ACollectionOfAtoms :) I have been preoccupied with other things to be honest.

If you want to take it over, feel free.

Exactly, you can switch the locale easily everywhere inside your application.

Would be nice to put an example in the documentation maybe ?

close, due to exists workaround the below:
https://kazupon.github.io/vue-i18n/en/lazy-loading.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

francoisromain picture francoisromain  路  19Comments

leo108 picture leo108  路  15Comments

gmarineau picture gmarineau  路  16Comments

qiaochangwei picture qiaochangwei  路  16Comments

bonchevski picture bonchevski  路  14Comments