Search code examples
javascriptpromisevue-resource

vue-i18n dynamic locale with promise doesn't update


I am testing vue-i18n in order to implement it for my future projects. I have a separate system to handle the translations, so I got remote json files. vue-i18n have a system to fetch the locale using a promise, explainations here.

I cannot use the fetch method because my files are outside so I got cross-origin troubles. Instead I do it with vue-resource, but I don't know why, when I set a new set of locale, it doesn't update automatically. bescause the default lang is en, when I load my en locale file, it does nothing. I have to change two times the config.lang to force update.

Several things:

  • A jsfiddle to test > http://jsfiddle.net/t4kdoqj7/3/ uncomment line 19 to reproduce the fix

  • Maybe it's just due to a bad using of vue-resource

  • I couldn't create a vue-i18n tag...

Thank you for your help !


Solution

  • Ok, I just found a hack :

    Set Vue.config.lang = '' before loading anything

    Here the fiddle (l9) > http://jsfiddle.net/t4kdoqj7/4/