Vue-i18n: Fallback language

Created on 10 Jun 2016  路  8Comments  路  Source: kazupon/vue-i18n

Hello,
is there a way to set a fallback language?
for example:

_en.json_

{
  "message": {
    "hello": "Hi"
  } 
}

_spanish.json_

{
  "message": { 
  } 
}
Vue.config.lang = 'spanish'
Vue.config.fallbackLang = 'en'

$t('message.hello')
// would return `Hi` 

Is there a way to do this ?

All 8 comments

This would be so useful please!

@kazupon Is this going to be implemented?

Guys, I created a solution on my own app and it was very helpful = ]

  1. Create a mixin that creates a translate method.
  2. Make it global.

mixins/translate.js

...
    let fallbackLang = config.fallbackLang; 
    return $t(key) || $t(key, fallbackLang);
...

use it:

inside a component:

    this.translate(key);

on a template:

    <div> translate(key) </div>

@kazupon @hiwye @rssfrncs

Maybe it helps figuring out how to implement on the lib = ]

@melloc01 That looks awesome, trying it out right now. Good job 馃憤

released v4.2.0

@kazupon this looks really good, but any chance it could still throw a warning in development?

really cool @kazupon, also it'd be cool to have warnings as @dansullivan86 pointed

released v.4.2.1
I supported fallback translation warning.
https://github.com/kazupon/vue-i18n/releases/tag/v4.2.1

Was this page helpful?
0 / 5 - 0 ratings