dkfbasel / vuex-i18n

Localization plugin for vue.js 2.0 using vuex as store
MIT License
666 stars 56 forks source link

Set Fallback language File #120

Open cingaldi opened 4 years ago

cingaldi commented 4 years ago

Hi,

I was looking for a way to set a fallback language when a translation is not found. Instead of adding a default value for each $t() , our workflow is to add a new string to the en.json file and then wait for the translator that sends back all updated language JSONs. This could save time because the developer adds a new string once (In default language JSON) instead of twice (in $t() and language JSON). I have in mind something like

import en from './lang/en.json'
import vuexI18n from 'vuex-i18n';

Vue.use(vuexI18n.plugin, store, {
    fallbackLanguage: en
});

Is it easy implementable?

tikiatua commented 4 years ago

I think this is actually already implemented. Let me check and get back to you in a few hours

tikiatua commented 4 years ago

Otherwise it should be rather easy to implement.

cingaldi commented 4 years ago

Thank you so much! I've seen this line and after inspection seems that does the job.Right?

tikiatua commented 4 years ago

Yepp. Exactly. You can set a fallback locale with $i18n.fallback(locale) inside a component or Vue.i18n.fallback(locale) when accessing the module directly.

tikiatua commented 4 years ago

The chain to find a translation message is actually like this:

Hope this clears things up a bit. We are still working on version 2 of the library with better documentation and more features (such as «embedded components»), but will probably hold it off until vue 3.0 is available.