Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Fallback language File #120

Open
cingaldi opened this issue Jan 22, 2020 · 5 comments
Open

Set Fallback language File #120

cingaldi opened this issue Jan 22, 2020 · 5 comments

Comments

@cingaldi
Copy link

cingaldi commented Jan 22, 2020

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
Copy link
Member

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

@tikiatua
Copy link
Member

Otherwise it should be rather easy to implement.

@cingaldi
Copy link
Author

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

@tikiatua
Copy link
Member

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
Copy link
Member

tikiatua commented Jan 22, 2020

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

  • Check default regional locale for the translation key, i.e. de-ch
  • If translation key was not found, check the non-regional locale, i.e. de
  • If translation key was still not found, check if a method is defined via the module property onTranslationNotFound and use the respective response message if one is returned. This can be used to asynchronously fetch missing translations
  • If no result was returned from the method or no method was specified, check the fallback locale for the translation key
  • If the key was not found in the fallback locale, return the specified default text for the translation key
  • If no default was specified, return the key itself

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants