Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vuex-i18n

Package Overview
Dependencies
Maintainers
3
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vuex-i18n - npm Package Compare versions

Comparing version 1.8.0 to 1.9.0

35

dist/vuex-i18n.cjs.js

@@ -522,3 +522,5 @@ 'use strict';

var checkKeyExists = function checkKeyExists(key) {
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'fallback';
// get the current language from the store

@@ -529,16 +531,29 @@ var locale = store.state[moduleName].locale;

// check if the language exists in the store.
if (translations.hasOwnProperty(locale) === false) {
// check the current translation
if (translations.hasOwnProperty(locale) && translations[locale].hasOwnProperty(key)) {
return true;
}
// check if a fallback locale exists
if (translations.hasOwnProperty(fallback) === false) {
return false;
}
if (scope == 'strict') {
return false;
}
// check the fallback locale for the key
return translations[fallback].hasOwnProperty(key);
// check any localized translations
var localeRegional = locale.split('-');
if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) && translations[localeRegional[0]].hasOwnProperty(key)) {
return true;
}
// check if the key exists in the store
return translations[locale].hasOwnProperty(key);
if (scope == 'locale') {
return false;
}
// check if a fallback locale exists
if (translations.hasOwnProperty(fallback) && translations[fallback].hasOwnProperty(key)) {
return true;
}
// key does not exist in the store
return false;
};

@@ -545,0 +560,0 @@

@@ -520,3 +520,5 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {

var checkKeyExists = function checkKeyExists(key) {
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'fallback';
// get the current language from the store

@@ -527,16 +529,29 @@ var locale = store.state[moduleName].locale;

// check if the language exists in the store.
if (translations.hasOwnProperty(locale) === false) {
// check the current translation
if (translations.hasOwnProperty(locale) && translations[locale].hasOwnProperty(key)) {
return true;
}
// check if a fallback locale exists
if (translations.hasOwnProperty(fallback) === false) {
return false;
}
if (scope == 'strict') {
return false;
}
// check the fallback locale for the key
return translations[fallback].hasOwnProperty(key);
// check any localized translations
var localeRegional = locale.split('-');
if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) && translations[localeRegional[0]].hasOwnProperty(key)) {
return true;
}
// check if the key exists in the store
return translations[locale].hasOwnProperty(key);
if (scope == 'locale') {
return false;
}
// check if a fallback locale exists
if (translations.hasOwnProperty(fallback) && translations[fallback].hasOwnProperty(key)) {
return true;
}
// key does not exist in the store
return false;
};

@@ -543,0 +558,0 @@

@@ -1,1 +0,1 @@

!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.vuexI18n=factory()}(this,function(){"use strict";function isArray(obj){return!!obj&&Array===obj.constructor}function isArray$1(obj){return!!obj&&Array===obj.constructor}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},i18nVuexModule={state:{locale:null,fallback:null,translations:{}},mutations:{SET_LOCALE:function(state,payload){state.locale=payload.locale},ADD_LOCALE:function(state,payload){var translations=flattenTranslations(payload.translations);if(state.translations.hasOwnProperty(payload.locale)){var existingTranslations=state.translations[payload.locale];state.translations[payload.locale]=Object.assign({},existingTranslations,translations)}else state.translations[payload.locale]=translations;try{state.translations.__ob__&&state.translations.__ob__.dep.notify()}catch(ex){}},REPLACE_LOCALE:function(state,payload){var translations=flattenTranslations(payload.translations);state.translations[payload.locale]=translations;try{state.translations.__ob__&&state.translations.__ob__.dep.notify()}catch(ex){}},REMOVE_LOCALE:function(state,payload){if(state.translations.hasOwnProperty(payload.locale)){state.locale===payload.locale&&(state.locale=null);var translationCopy=Object.assign({},state.translations);delete translationCopy[payload.locale],state.translations=translationCopy}},SET_FALLBACK_LOCALE:function(state,payload){state.fallback=payload.locale}},actions:{setLocale:function(context,payload){context.commit({type:"SET_LOCALE",locale:payload.locale})},addLocale:function(context,payload){context.commit({type:"ADD_LOCALE",locale:payload.locale,translations:payload.translations})},replaceLocale:function(context,payload){context.commit({type:"REPLACE_LOCALE",locale:payload.locale,translations:payload.translations})},removeLocale:function(context,payload){context.commit({type:"REMOVE_LOCALE",locale:payload.locale,translations:payload.translations})},setFallbackLocale:function(context,payload){context.commit({type:"SET_FALLBACK_LOCALE",locale:payload.locale})}}},flattenTranslations=function flattenTranslations(translations){var toReturn={};for(var i in translations)if(translations.hasOwnProperty(i)){var objType=_typeof(translations[i]);if(isArray(translations[i])){for(var count=translations[i].length,index=0;index<count;index++)if("string"!==_typeof(translations[i][index])){console.warn("vuex-i18n:","currently only arrays of strings are fully supported",translations[i]);break}toReturn[i]=translations[i]}else if("object"==objType&&null!==objType){var flatObject=flattenTranslations(translations[i]);for(var x in flatObject)flatObject.hasOwnProperty(x)&&(toReturn[i+"."+x]=flatObject[x])}else toReturn[i]=translations[i]}return toReturn},plurals={getTranslationIndex:function(languageCode,n){switch(languageCode){case"ay":case"bo":case"cgg":case"dz":case"fa":case"id":case"ja":case"jbo":case"ka":case"kk":case"km":case"ko":case"ky":case"lo":case"ms":case"my":case"sah":case"su":case"th":case"tt":case"ug":case"vi":case"wo":case"zh":return 0;case"is":return n%10!=1||n%100==11?1:0;case"jv":return 0!==n?1:0;case"mk":return 1===n||n%10==1?0:1;case"ach":case"ak":case"am":case"arn":case"br":case"fil":case"fr":case"gun":case"ln":case"mfe":case"mg":case"mi":case"oc":case"pt_BR":case"tg":case"ti":case"tr":case"uz":case"wa":case"zh":return n>1?1:0;case"lv":return n%10==1&&n%100!=11?0:0!==n?1:2;case"lt":return n%10==1&&n%100!=11?0:n%10>=2&&(n%100<10||n%100>=20)?1:2;case"be":case"bs":case"hr":case"ru":case"sr":case"uk":return n%10==1&&n%100!=11?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2;case"mnk":return 0===n?0:1===n?1:2;case"ro":return 1===n?0:0===n||n%100>0&&n%100<20?1:2;case"pl":return 1===n?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2;case"cs":case"sk":return 1===n?0:n>=2&&n<=4?1:2;case"csb":return 1===n?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2;case"sl":return n%100==1?0:n%100==2?1:n%100==3||n%100==4?2:3;case"mt":return 1===n?0:0===n||n%100>1&&n%100<11?1:n%100>10&&n%100<20?2:3;case"gd":return 1===n||11===n?0:2===n||12===n?1:n>2&&n<20?2:3;case"cy":return 1===n?0:2===n?1:8!==n&&11!==n?2:3;case"kw":return 1===n?0:2===n?1:3===n?2:3;case"ga":return 1===n?0:2===n?1:n>2&&n<7?2:n>6&&n<11?3:4;case"ar":return 0===n?0:1===n?1:2===n?2:n%100>=3&&n%100<=10?3:n%100>=11?4:5;default:return 1!==n?1:0}}},VuexI18nPlugin={};VuexI18nPlugin.install=function(Vue,store,config){"string"!=typeof arguments[2]&&"string"!=typeof arguments[3]||(console.warn("VuexI18nPlugin: Registering the plugin with a string for `moduleName` or `identifiers` is deprecated. Use a configuration object instead.","https://github.com/dkfbasel/vuex-i18n#setup"),config={moduleName:arguments[2],identifiers:arguments[3]});var mergedConfig=Object.assign({moduleName:"i18n",identifiers:["{","}"],onTranslationNotFound:function(){}},config),moduleName=mergedConfig.moduleName,identifiers=mergedConfig.identifiers,onTranslationNotFound=mergedConfig.onTranslationNotFound;if("function"!=typeof onTranslationNotFound&&(console.error("i18n config option onTranslationNotFound must be a function"),onTranslationNotFound=function(){}),store.registerModule(moduleName,i18nVuexModule),!1===store.state.hasOwnProperty(moduleName))return console.error("i18n vuex module is not correctly initialized. Please check the module name:",moduleName),Vue.prototype.$i18n=function(key){return key},Vue.prototype.$getLanguage=function(){return null},void(Vue.prototype.$setLanguage=function(){console.error("i18n vuex module is not correctly initialized")});var render=renderFn(identifiers),translate=function(){var locale=store.state[moduleName].locale;return translateInLanguage.apply(void 0,[locale].concat(Array.prototype.slice.call(arguments)))},translateInLanguage=function(locale){var args=arguments,key="",defaultValue="",options={},pluralization=null,count=args.length;if(count>=3&&"string"==typeof args[2]?(key=args[1],defaultValue=args[2],count>3&&(options=args[3]),count>4&&(pluralization=args[4])):(defaultValue=key=args[1],count>2&&(options=args[2]),count>3&&(pluralization=args[3])),!locale)return console.warn("i18n locale is not set when trying to access translations:",key),defaultValue;var translations=store.state[moduleName].translations,fallback=store.state[moduleName].fallback,localeRegional=locale.split("-"),translationExists=!0;return!1===translations.hasOwnProperty(locale)?translationExists=!1:!1===translations[locale].hasOwnProperty(key)&&(translationExists=!1),!0===translationExists?render(locale,translations[locale][key],options,pluralization):(!1===translationExists&&onTranslationNotFound(locale,key),localeRegional.length>1&&!0===translations.hasOwnProperty(localeRegional[0])&&!0===translations[localeRegional[0]].hasOwnProperty(key)?render(localeRegional[0],translations[localeRegional[0]][key],options,pluralization):!1===translations.hasOwnProperty(fallback)?render(locale,defaultValue,options,pluralization):!1===translations[fallback].hasOwnProperty(key)?render(fallback,defaultValue,options,pluralization):render(locale,translations[fallback][key],options,pluralization))},checkKeyExists=function(key){var locale=store.state[moduleName].locale,fallback=store.state[moduleName].fallback,translations=store.state[moduleName].translations;return!1===translations.hasOwnProperty(locale)?!1!==translations.hasOwnProperty(fallback)&&translations[fallback].hasOwnProperty(key):translations[locale].hasOwnProperty(key)},setFallbackLocale=function(locale){store.dispatch({type:"setFallbackLocale",locale:locale})},setLocale=function(locale){store.dispatch({type:"setLocale",locale:locale})},getLocale=function(){return store.state[moduleName].locale},addLocale=function(locale,translations){return store.dispatch({type:"addLocale",locale:locale,translations:translations})},replaceLocale=function(locale,translations){return store.dispatch({type:"replaceLocale",locale:locale,translations:translations})},removeLocale=function(locale){store.state[moduleName].translations.hasOwnProperty(locale)&&store.dispatch({type:"removeLocale",locale:locale})},phaseOutExistsFn=function(locale){return console.warn("$i18n.exists is depreceated. Please use $i18n.localeExists instead. It provides exatly the same functionality."),checkLocaleExists(locale)},checkLocaleExists=function(locale){return store.state[moduleName].translations.hasOwnProperty(locale)};Vue.prototype.$i18n={locale:getLocale,set:setLocale,add:addLocale,replace:replaceLocale,remove:removeLocale,fallback:setFallbackLocale,localeExists:checkLocaleExists,keyExists:checkKeyExists,exists:phaseOutExistsFn},Vue.i18n={locale:getLocale,set:setLocale,add:addLocale,replace:replaceLocale,remove:removeLocale,fallback:setFallbackLocale,translate:translate,translateIn:translateInLanguage,localeExists:checkLocaleExists,keyExists:checkKeyExists,exists:phaseOutExistsFn},Vue.prototype.$t=translate,Vue.prototype.$tlang=translateInLanguage,Vue.filter("translate",translate)};var renderFn=function(identifiers){null!=identifiers&&2==identifiers.length||console.warn("You must specify the start and end character identifying variable substitutions");var matcher=new RegExp(identifiers[0]+"\\w+"+identifiers[1],"g"),replace=function(translation,replacements){var warn=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return translation.replace?translation.replace(matcher,function(placeholder){var key=placeholder.replace(identifiers[0],"").replace(identifiers[1],"");return void 0!==replacements[key]?replacements[key]:(!0===warn&&(console.group?console.group("Not all placeholders found"):console.warn("Not all placeholders found"),console.warn("Text:",translation),console.warn("Placeholder:",placeholder),console.groupEnd&&console.groupEnd()),placeholder)}):translation};return function(locale,translation){var replacements=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},pluralization=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,objType=void 0===translation?"undefined":_typeof(translation),pluralizationType=void 0===pluralization?"undefined":_typeof(pluralization),replacedText=function(){return isArray$1(translation)?translation.map(function(item){return replace(item,replacements,!1)}):"string"===objType?replace(translation,replacements,!0):void 0};if(null===pluralization)return replacedText();if("number"!==pluralizationType)return console.warn("pluralization is not a number"),replacedText();var translatedText=replacedText().split(":::"),index=plurals.getTranslationIndex(locale,pluralization);return void 0===translatedText[index]?(console.warn("no pluralized translation provided in ",translation),translatedText[0].trim()):translatedText[index].trim()}};return{store:i18nVuexModule,plugin:VuexI18nPlugin}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.vuexI18n=t()}(this,function(){"use strict";function e(e){return!!e&&Array===e.constructor}function t(e){return!!e&&Array===e.constructor}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a={state:{locale:null,fallback:null,translations:{}},mutations:{SET_LOCALE:function e(t,n){t.locale=n.locale},ADD_LOCALE:function e(t,n){var a=o(n.translations);if(t.translations.hasOwnProperty(n.locale)){var r=t.translations[n.locale];t.translations[n.locale]=Object.assign({},r,a)}else t.translations[n.locale]=a;try{t.translations.__ob__&&t.translations.__ob__.dep.notify()}catch(e){}},REPLACE_LOCALE:function e(t,n){var a=o(n.translations);t.translations[n.locale]=a;try{t.translations.__ob__&&t.translations.__ob__.dep.notify()}catch(e){}},REMOVE_LOCALE:function e(t,n){if(t.translations.hasOwnProperty(n.locale)){t.locale===n.locale&&(t.locale=null);var a=Object.assign({},t.translations);delete a[n.locale],t.translations=a}},SET_FALLBACK_LOCALE:function e(t,n){t.fallback=n.locale}},actions:{setLocale:function e(t,n){t.commit({type:"SET_LOCALE",locale:n.locale})},addLocale:function e(t,n){t.commit({type:"ADD_LOCALE",locale:n.locale,translations:n.translations})},replaceLocale:function e(t,n){t.commit({type:"REPLACE_LOCALE",locale:n.locale,translations:n.translations})},removeLocale:function e(t,n){t.commit({type:"REMOVE_LOCALE",locale:n.locale,translations:n.translations})},setFallbackLocale:function e(t,n){t.commit({type:"SET_FALLBACK_LOCALE",locale:n.locale})}}},o=function t(a){var o={};for(var r in a)if(a.hasOwnProperty(r)){var s=n(a[r]);if(e(a[r])){for(var l=a[r].length,c=0;c<l;c++){var i=n(a[r][c]);if("string"!==i){console.warn("vuex-i18n:","currently only arrays of strings are fully supported",a[r]);break}}o[r]=a[r]}else if("object"==s&&null!==s){var u=t(a[r]);for(var f in u)u.hasOwnProperty(f)&&(o[r+"."+f]=u[f])}else o[r]=a[r]}return o},r={getTranslationIndex:function e(t,n){switch(t){case"ay":case"bo":case"cgg":case"dz":case"fa":case"id":case"ja":case"jbo":case"ka":case"kk":case"km":case"ko":case"ky":case"lo":case"ms":case"my":case"sah":case"su":case"th":case"tt":case"ug":case"vi":case"wo":case"zh":return 0;case"is":return n%10!=1||n%100==11?1:0;case"jv":return 0!==n?1:0;case"mk":return 1===n||n%10==1?0:1;case"ach":case"ak":case"am":case"arn":case"br":case"fil":case"fr":case"gun":case"ln":case"mfe":case"mg":case"mi":case"oc":case"pt_BR":case"tg":case"ti":case"tr":case"uz":case"wa":case"zh":return n>1?1:0;case"lv":return n%10==1&&n%100!=11?0:0!==n?1:2;case"lt":return n%10==1&&n%100!=11?0:n%10>=2&&(n%100<10||n%100>=20)?1:2;case"be":case"bs":case"hr":case"ru":case"sr":case"uk":return n%10==1&&n%100!=11?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2;case"mnk":return 0===n?0:1===n?1:2;case"ro":return 1===n?0:0===n||n%100>0&&n%100<20?1:2;case"pl":return 1===n?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2;case"cs":case"sk":return 1===n?0:n>=2&&n<=4?1:2;case"csb":return 1===n?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2;case"sl":return n%100==1?0:n%100==2?1:n%100==3||n%100==4?2:3;case"mt":return 1===n?0:0===n||n%100>1&&n%100<11?1:n%100>10&&n%100<20?2:3;case"gd":return 1===n||11===n?0:2===n||12===n?1:n>2&&n<20?2:3;case"cy":return 1===n?0:2===n?1:8!==n&&11!==n?2:3;case"kw":return 1===n?0:2===n?1:3===n?2:3;case"ga":return 1===n?0:2===n?1:n>2&&n<7?2:n>6&&n<11?3:4;case"ar":return 0===n?0:1===n?1:2===n?2:n%100>=3&&n%100<=10?3:n%100>=11?4:5;default:return 1!==n?1:0}}},s={};s.install=function e(t,n,o){"string"!=typeof arguments[2]&&"string"!=typeof arguments[3]||(console.warn("VuexI18nPlugin: Registering the plugin with a string for `moduleName` or `identifiers` is deprecated. Use a configuration object instead.","https://github.com/dkfbasel/vuex-i18n#setup"),o={moduleName:arguments[2],identifiers:arguments[3]});var r=Object.assign({moduleName:"i18n",identifiers:["{","}"],onTranslationNotFound:function e(){}},o),s=r.moduleName,c=r.identifiers,i=r.onTranslationNotFound;if("function"!=typeof i&&(console.error("i18n config option onTranslationNotFound must be a function"),i=function e(){}),n.registerModule(s,a),!1===n.state.hasOwnProperty(s))return console.error("i18n vuex module is not correctly initialized. Please check the module name:",s),t.prototype.$i18n=function(e){return e},t.prototype.$getLanguage=function(){return null},void(t.prototype.$setLanguage=function(){console.error("i18n vuex module is not correctly initialized")});var u=l(c),f=function e(){var t=n.state[s].locale;return p.apply(void 0,[t].concat(Array.prototype.slice.call(arguments)))},p=function e(t){var a=arguments,o="",r="",l={},c=null,f=a.length;if(f>=3&&"string"==typeof a[2]?(o=a[1],r=a[2],f>3&&(l=a[3]),f>4&&(c=a[4])):(o=a[1],r=o,f>2&&(l=a[2]),f>3&&(c=a[3])),!t)return console.warn("i18n locale is not set when trying to access translations:",o),r;var p=n.state[s].translations,d=n.state[s].fallback,y=t.split("-"),h=!0;return!1===p.hasOwnProperty(t)?h=!1:!1===p[t].hasOwnProperty(o)&&(h=!1),!0===h?u(t,p[t][o],l,c):(!1===h&&i(t,o),y.length>1&&!0===p.hasOwnProperty(y[0])&&!0===p[y[0]].hasOwnProperty(o)?u(y[0],p[y[0]][o],l,c):!1===p.hasOwnProperty(d)?u(t,r,l,c):!1===p[d].hasOwnProperty(o)?u(d,r,l,c):u(t,p[d][o],l,c))},d=function e(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"fallback",o=n.state[s].locale,r=n.state[s].fallback,l=n.state[s].translations;if(l.hasOwnProperty(o)&&l[o].hasOwnProperty(t))return!0;if("strict"==a)return!1;var c=o.split("-");return!!(c.length>1&&l.hasOwnProperty(c[0])&&l[c[0]].hasOwnProperty(t))||"locale"!=a&&!(!l.hasOwnProperty(r)||!l[r].hasOwnProperty(t))},y=function e(t){n.dispatch({type:"setFallbackLocale",locale:t})},h=function e(t){n.dispatch({type:"setLocale",locale:t})},m=function e(){return n.state[s].locale},g=function e(t,a){return n.dispatch({type:"addLocale",locale:t,translations:a})},v=function e(t,a){return n.dispatch({type:"replaceLocale",locale:t,translations:a})},b=function e(t){n.state[s].translations.hasOwnProperty(t)&&n.dispatch({type:"removeLocale",locale:t})},L=function e(t){return console.warn("$i18n.exists is depreceated. Please use $i18n.localeExists instead. It provides exatly the same functionality."),w(t)},w=function e(t){return n.state[s].translations.hasOwnProperty(t)};t.prototype.$i18n={locale:m,set:h,add:g,replace:v,remove:b,fallback:y,localeExists:w,keyExists:d,exists:L},t.i18n={locale:m,set:h,add:g,replace:v,remove:b,fallback:y,translate:f,translateIn:p,localeExists:w,keyExists:d,exists:L},t.prototype.$t=f,t.prototype.$tlang=p,t.filter("translate",f)};var l=function e(a){null!=a&&2==a.length||console.warn("You must specify the start and end character identifying variable substitutions");var o=new RegExp(a[0]+"\\w+"+a[1],"g"),s=function e(t,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return t.replace?t.replace(o,function(e){var o=e.replace(a[0],"").replace(a[1],"");return void 0!==n[o]?n[o]:(!0===r&&(console.group?console.group("Not all placeholders found"):console.warn("Not all placeholders found"),console.warn("Text:",t),console.warn("Placeholder:",e),console.groupEnd&&console.groupEnd()),e)}):t};return function e(a,o){var l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},c=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=void 0===o?"undefined":n(o),u=void 0===c?"undefined":n(c),f=function e(){return t(o)?o.map(function(e){return s(e,l,!1)}):"string"===i?s(o,l,!0):void 0};if(null===c)return f();if("number"!==u)return console.warn("pluralization is not a number"),f();var p=f().split(":::"),d=r.getTranslationIndex(a,c);return void 0===p[d]?(console.warn("no pluralized translation provided in ",o),p[0].trim()):p[d].trim()}};return{store:a,plugin:s}});

@@ -526,3 +526,5 @@ (function (global, factory) {

var checkKeyExists = function checkKeyExists(key) {
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'fallback';
// get the current language from the store

@@ -533,16 +535,29 @@ var locale = store.state[moduleName].locale;

// check if the language exists in the store.
if (translations.hasOwnProperty(locale) === false) {
// check the current translation
if (translations.hasOwnProperty(locale) && translations[locale].hasOwnProperty(key)) {
return true;
}
// check if a fallback locale exists
if (translations.hasOwnProperty(fallback) === false) {
return false;
}
if (scope == 'strict') {
return false;
}
// check the fallback locale for the key
return translations[fallback].hasOwnProperty(key);
// check any localized translations
var localeRegional = locale.split('-');
if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) && translations[localeRegional[0]].hasOwnProperty(key)) {
return true;
}
// check if the key exists in the store
return translations[locale].hasOwnProperty(key);
if (scope == 'locale') {
return false;
}
// check if a fallback locale exists
if (translations.hasOwnProperty(fallback) && translations[fallback].hasOwnProperty(key)) {
return true;
}
// key does not exist in the store
return false;
};

@@ -549,0 +564,0 @@

{
"name": "vuex-i18n",
"version": "1.8.0",
"version": "1.9.0",
"description": "Easy localization for vue-components using vuex as data store",

@@ -5,0 +5,0 @@ "directories": {

@@ -41,2 +41,6 @@ # vuex-i18n

// please note that the default format for the plugin is in es2015
// for use in server side rendering (such as nuxt), the umd version should be loaded like this
// import vuexI18n from 'vuex-i18n/dist/vuex-i18n.umd.js';
// initialize the vuex store using the vuex module. note that you can change the

@@ -207,2 +211,9 @@ // name of the module if you wish

```javascript
// translate the given key
$i18n.$t(), Vue.i18n.translate()
// translate the given key in a specific locale
$i18n.$tlang(), Vue.i18n.translateIn()
// get the current locale

@@ -222,16 +233,28 @@ $i18n.locale(), Vue.i18n.locale()

// remove the given locale from the store
$i18n.remove(locale), Vue.i18n.remove(locale)
// set a fallback locale if translation for current locale does not exist
$i18n.fallback(locale), Vue.i18n.fallback(locale)
// check if the given locale translations are present in the store
$i18n.localeExists(locale), Vue.i18n.localeExists(locale)
// check if the given key is available in the current or fallback locale
// check if the given key is available (will check current, regional and fallback locale)
$i18n.keyExists(key), Vue.i18n.keyExists(key)
// remove the given locale from the store
$i18n.remove(locale), Vue.i18n.remove(locale)
// optional with a second parameter to limit the scope
// strict: only current locale (exact match)
// locale: current locale and parent language locale (i.e. en-us & en)
// fallback: current locale, parent language locale and fallback locale
// the default is fallback
$i18n.keyExists(key, 'strict'), $i18n.keyExists(key, 'locale'), $i18n.keyExists(key, 'fallback'),
// set a fallback locale if translation for current locale does not exist
$i18n.fallback(locale), Vue.i18n.fallback(locale)
```
## Third-Party Integration
Thanks to Liip Team Amboss for developing an interactive translation manager for node.js. You can find it at https://github.com/liip-amboss/locale-man.
## Contributions
Any comments or suggestions are very welcome.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc