panter / vue-i18next

Internationalization for vue using the i18next i18n ecosystem.
https://panter.github.io/vue-i18next/
176 stars 47 forks source link

key fallback #45

Closed steevhise closed 5 years ago

steevhise commented 5 years ago

I'm tryign to do key-fallback, as described here https://www.i18next.com/principles/fallback#key-fallback, using your library, but i just get an empty result back rather than the key when a translation value is missing. My config is as follows:

Vue.i18nOptions = {
   debug: true,
    lng: window.language,
    preload: [ window.language ],
    load: 'languageOnly',
    fallbackLng: false,    // the key is the fallback
    fallbackNS: false,      // not  using namespaces
    // allow keys to be phrases having `:`, `.`
    nsSeparator: false,
    keySeparator: false,
    backend: {
        loadPath: '/translations/{{lng}}.json'
    }
};

i18next
    .use(XHR)
    .init(Vue.i18nOptions);

This works fine as long as there's a value for every key. For ones without, I want to fallback to the key but I just get nothing. Is key-fallback supported by your library and if so what am I doing wrong? thanks.

steevhise commented 5 years ago

interestingly, a completely missing key DOES fallback correctly, it's only when the key is present in the translation resource AND there's no value for it that i get an empty result.

steevhise commented 5 years ago

Well well, it looks like i was leaving out one more config option: returnEmptyString: false. Not your problem, but unfortunate that this isn't mentioned in the i18next docs!

claudiocro commented 5 years ago

@steevhise thank for sharing your solution.

I think the docs could mentions this config options so that users are aware of it.