From e66c86d7a558c40f2be9308846994ca2236c981b Mon Sep 17 00:00:00 2001 From: tikiatua Date: Fri, 4 Aug 2017 14:53:38 +0200 Subject: [PATCH] new build --- dist/vuex-i18n.cjs.js | 19 +++++++++++++++---- dist/vuex-i18n.es.js | 19 +++++++++++++++---- dist/vuex-i18n.min.js | 19 +++++++++++++++---- package.json | 2 +- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/dist/vuex-i18n.cjs.js b/dist/vuex-i18n.cjs.js index db338e3..051cb17 100644 --- a/dist/vuex-i18n.cjs.js +++ b/dist/vuex-i18n.cjs.js @@ -394,17 +394,22 @@ VuexI18nPlugin.install = function install(Vue, store) { } } - // get the current language from the store - var fallback = store.state[moduleName].fallback; + // get the translations from the store var translations = store.state[moduleName].translations; + // get the last resort fallback from the store + var fallback = store.state[moduleName].fallback; + + // split locale by - to support partial fallback for regional locales + // like de-CH, en-UK + var localeRegional = locale.split('-'); + // flag for translation to exist or not var translationExist = true; // check if the language exists in the store. return the key if not if (translations.hasOwnProperty(locale) === false) { translationExist = false; - // check if the key exists in the store. return the key if not } else if (translations[locale].hasOwnProperty(key) === false) { translationExist = false; @@ -415,6 +420,12 @@ VuexI18nPlugin.install = function install(Vue, store) { return render(locale, translations[locale][key], options, pluralization); } + // check if a regional locale translation would be available for the key + // i.e. de for de-CH + if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) === true && translations[localeRegional[0]].hasOwnProperty(key) === true) { + return render(localeRegional[0], translations[localeRegional[0]][key], options, pluralization); + } + // check if a vaild fallback exists in the store. // return the default value if not if (translations.hasOwnProperty(fallback) === false) { @@ -424,7 +435,7 @@ VuexI18nPlugin.install = function install(Vue, store) { // check if the key exists in the fallback locale in the store. // return the default value if not if (translations[fallback].hasOwnProperty(key) === false) { - return render(locale, defaultValue, options, pluralization); + return render(fallback, defaultValue, options, pluralization); } return render(locale, translations[fallback][key], options, pluralization); diff --git a/dist/vuex-i18n.es.js b/dist/vuex-i18n.es.js index afcd156..bd8e4dc 100644 --- a/dist/vuex-i18n.es.js +++ b/dist/vuex-i18n.es.js @@ -392,17 +392,22 @@ VuexI18nPlugin.install = function install(Vue, store) { } } - // get the current language from the store - var fallback = store.state[moduleName].fallback; + // get the translations from the store var translations = store.state[moduleName].translations; + // get the last resort fallback from the store + var fallback = store.state[moduleName].fallback; + + // split locale by - to support partial fallback for regional locales + // like de-CH, en-UK + var localeRegional = locale.split('-'); + // flag for translation to exist or not var translationExist = true; // check if the language exists in the store. return the key if not if (translations.hasOwnProperty(locale) === false) { translationExist = false; - // check if the key exists in the store. return the key if not } else if (translations[locale].hasOwnProperty(key) === false) { translationExist = false; @@ -413,6 +418,12 @@ VuexI18nPlugin.install = function install(Vue, store) { return render(locale, translations[locale][key], options, pluralization); } + // check if a regional locale translation would be available for the key + // i.e. de for de-CH + if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) === true && translations[localeRegional[0]].hasOwnProperty(key) === true) { + return render(localeRegional[0], translations[localeRegional[0]][key], options, pluralization); + } + // check if a vaild fallback exists in the store. // return the default value if not if (translations.hasOwnProperty(fallback) === false) { @@ -422,7 +433,7 @@ VuexI18nPlugin.install = function install(Vue, store) { // check if the key exists in the fallback locale in the store. // return the default value if not if (translations[fallback].hasOwnProperty(key) === false) { - return render(locale, defaultValue, options, pluralization); + return render(fallback, defaultValue, options, pluralization); } return render(locale, translations[fallback][key], options, pluralization); diff --git a/dist/vuex-i18n.min.js b/dist/vuex-i18n.min.js index a01d084..99c1301 100644 --- a/dist/vuex-i18n.min.js +++ b/dist/vuex-i18n.min.js @@ -398,17 +398,22 @@ VuexI18nPlugin.install = function install(Vue, store) { } } - // get the current language from the store - var fallback = store.state[moduleName].fallback; + // get the translations from the store var translations = store.state[moduleName].translations; + // get the last resort fallback from the store + var fallback = store.state[moduleName].fallback; + + // split locale by - to support partial fallback for regional locales + // like de-CH, en-UK + var localeRegional = locale.split('-'); + // flag for translation to exist or not var translationExist = true; // check if the language exists in the store. return the key if not if (translations.hasOwnProperty(locale) === false) { translationExist = false; - // check if the key exists in the store. return the key if not } else if (translations[locale].hasOwnProperty(key) === false) { translationExist = false; @@ -419,6 +424,12 @@ VuexI18nPlugin.install = function install(Vue, store) { return render(locale, translations[locale][key], options, pluralization); } + // check if a regional locale translation would be available for the key + // i.e. de for de-CH + if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) === true && translations[localeRegional[0]].hasOwnProperty(key) === true) { + return render(localeRegional[0], translations[localeRegional[0]][key], options, pluralization); + } + // check if a vaild fallback exists in the store. // return the default value if not if (translations.hasOwnProperty(fallback) === false) { @@ -428,7 +439,7 @@ VuexI18nPlugin.install = function install(Vue, store) { // check if the key exists in the fallback locale in the store. // return the default value if not if (translations[fallback].hasOwnProperty(key) === false) { - return render(locale, defaultValue, options, pluralization); + return render(fallback, defaultValue, options, pluralization); } return render(locale, translations[fallback][key], options, pluralization); diff --git a/package.json b/package.json index 642645c..ac897da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vuex-i18n", - "version": "1.5.1", + "version": "1.6.0", "description": "Easy localization for vue-components using vuex as data store", "directories": { "test": "test"