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.10.10 to 1.11.0

14

dist/vuex-i18n.cjs.js

@@ -410,2 +410,3 @@ 'use strict';

translateFilterName: 'translate',
translateInFilterName: 'translateIn',
onTranslationNotFound: function onTranslationNotFound() {}

@@ -416,3 +417,4 @@ }, config); // define module name and identifiers as constants to prevent any changes

var identifiers = config.identifiers;
var translateFilterName = config.translateFilterName; // initialize the onTranslationNotFound function and make sure it is actually
var translateFilterName = config.translateFilterName;
var translateInFilterName = config.translateInFilterName; // initialize the onTranslationNotFound function and make sure it is actually
// a function

@@ -558,2 +560,11 @@

return render(locale, translations[fallback][key], options, pluralization);
}; // add a filter function to translate in a given locale (i.e. {{ 'something' | translateIn('en') }})
var translateInLanguageFilter = function translateInLanguageFilter(key, locale) {
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
return translateInLanguage.apply(void 0, [locale, key].concat(args));
}; // check if the given key exists in the current locale

@@ -698,2 +709,3 @@

Vue.filter(translateFilterName, translate);
Vue.filter(translateInFilterName, translateInLanguageFilter);
}; // renderFn will initialize a function to render the variable substitutions in

@@ -700,0 +712,0 @@ // the translation string. identifiers specify the tags will be used to find

@@ -408,2 +408,3 @@ function _typeof(obj) {

translateFilterName: 'translate',
translateInFilterName: 'translateIn',
onTranslationNotFound: function onTranslationNotFound() {}

@@ -414,3 +415,4 @@ }, config); // define module name and identifiers as constants to prevent any changes

var identifiers = config.identifiers;
var translateFilterName = config.translateFilterName; // initialize the onTranslationNotFound function and make sure it is actually
var translateFilterName = config.translateFilterName;
var translateInFilterName = config.translateInFilterName; // initialize the onTranslationNotFound function and make sure it is actually
// a function

@@ -556,2 +558,11 @@

return render(locale, translations[fallback][key], options, pluralization);
}; // add a filter function to translate in a given locale (i.e. {{ 'something' | translateIn('en') }})
var translateInLanguageFilter = function translateInLanguageFilter(key, locale) {
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
return translateInLanguage.apply(void 0, [locale, key].concat(args));
}; // check if the given key exists in the current locale

@@ -696,2 +707,3 @@

Vue.filter(translateFilterName, translate);
Vue.filter(translateInFilterName, translateInLanguageFilter);
}; // renderFn will initialize a function to render the variable substitutions in

@@ -698,0 +710,0 @@ // the translation string. identifiers specify the tags will be used to find

2

dist/vuex-i18n.min.js

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

!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):(global=global||self).vuexI18n=factory()}(this,function(){"use strict";function _typeof(obj){return(_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})(obj)}var i18nVuexModule={namespaced:!0,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 obj,toReturn={};for(var i in translations)if(translations.hasOwnProperty(i)){var objType=_typeof(translations[i]);if((obj=translations[i])&&Array===obj.constructor){for(var count=translations[i].length,index=0;index<count;index++){if("string"!==_typeof(translations[i][index])){console.warn("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};var 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={install:function(Vue,store,config){"string"!=typeof arguments[2]&&"string"!=typeof arguments[3]||(console.warn("i18n: Registering the plugin vuex-i18n 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 moduleName=(config=Object.assign({warnings:!0,moduleName:"i18n",identifiers:["{","}"],preserveState:!1,translateFilterName:"translate",onTranslationNotFound:function(){}},config)).moduleName,identifiers=config.identifiers,translateFilterName=config.translateFilterName,onTranslationNotFound=config.onTranslationNotFound;if("function"!=typeof onTranslationNotFound&&(console.error("i18n: i18n config option onTranslationNotFound must be a function"),onTranslationNotFound=function(){}),store.registerModule(moduleName,i18nVuexModule,{preserveState:config.preserveState}),!1===store.state.hasOwnProperty(moduleName))return console.error("i18n: 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: i18n vuex module is not correctly initialized")});var render=renderFn(identifiers,config.warnings),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 config.warnings&&console.warn("i18n: 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;if(!1===translations.hasOwnProperty(locale)?translationExists=!1:!1===translations[locale].hasOwnProperty(key)&&(translationExists=!1),!0===translationExists)return render(locale,translations[locale][key],options,pluralization);if(localeRegional.length>1&&!0===translations.hasOwnProperty(localeRegional[0])&&!0===translations[localeRegional[0]].hasOwnProperty(key))return render(localeRegional[0],translations[localeRegional[0]][key],options,pluralization);var asyncTranslation=onTranslationNotFound(locale,key,defaultValue);return asyncTranslation&&Promise.resolve(asyncTranslation).then(function(value){var additionalTranslations={};additionalTranslations[key]=value,addLocale(locale,additionalTranslations)}),!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 scope=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"fallback",locale=store.state[moduleName].locale,fallback=store.state[moduleName].fallback,translations=store.state[moduleName].translations;if(translations.hasOwnProperty(locale)&&translations[locale].hasOwnProperty(key))return!0;if("strict"==scope)return!1;var localeRegional=locale.split("-");return!!(localeRegional.length>1&&translations.hasOwnProperty(localeRegional[0])&&translations[localeRegional[0]].hasOwnProperty(key))||"locale"!=scope&&!(!translations.hasOwnProperty(fallback)||!translations[fallback].hasOwnProperty(key))},setFallbackLocale=function(locale){store.dispatch({type:"".concat(moduleName,"/setFallbackLocale"),locale:locale})},setLocale=function(locale){store.dispatch({type:"".concat(moduleName,"/setLocale"),locale:locale})},getLocale=function(){return store.state[moduleName].locale},getLocales=function(){return Object.keys(store.state[moduleName].translations)},addLocale=function(locale,translations){return store.dispatch({type:"".concat(moduleName,"/addLocale"),locale:locale,translations:translations})},replaceLocale=function(locale,translations){return store.dispatch({type:"".concat(moduleName,"/replaceLocale"),locale:locale,translations:translations})},removeLocale=function(locale){store.state[moduleName].translations.hasOwnProperty(locale)&&store.dispatch({type:"".concat(moduleName,"/removeLocale"),locale:locale})},phaseOutExistsFn=function(locale){return config.warnings&&console.warn("i18n: $i18n.exists is depreceated. Please use $i18n.localeExists instead. It provides exactly the same functionality."),checkLocaleExists(locale)},checkLocaleExists=function(locale){return store.state[moduleName].translations.hasOwnProperty(locale)};Vue.prototype.$i18n={locale:getLocale,locales:getLocales,set:setLocale,add:addLocale,replace:replaceLocale,remove:removeLocale,fallback:setFallbackLocale,localeExists:checkLocaleExists,keyExists:checkKeyExists,translate:translate,translateIn:translateInLanguage,exists:phaseOutExistsFn},Vue.i18n={locale:getLocale,locales:getLocales,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(translateFilterName,translate)}},renderFn=function(identifiers){var warnings=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];null!=identifiers&&2==identifiers.length||console.warn("i18n: You must specify the start and end character identifying variable substitutions");var matcher=new RegExp(identifiers[0]+"{1}(\\w{1}|\\w.+?)"+identifiers[1]+"{1}","g"),replace=function(translation,replacements){return translation.replace?translation.replace(matcher,function(placeholder){var key=placeholder.replace(identifiers[0],"").replace(identifiers[1],"");return void 0!==replacements[key]?replacements[key]:(warnings&&(console.group?console.group("i18n: Not all placeholders found"):console.warn("i18n: 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=_typeof(translation),pluralizationType=_typeof(pluralization),resolvePlaceholders=function(){return isArray$1(translation)?translation.map(function(item){return replace(item,replacements)}):"string"===objType?replace(translation,replacements):void 0};if(null===pluralization)return resolvePlaceholders();if("number"!==pluralizationType)return warnings&&console.warn("i18n: pluralization is not a number"),resolvePlaceholders();var resolvedTranslation=resolvePlaceholders(),pluralizations=null;pluralizations=isArray$1(resolvedTranslation)&&resolvedTranslation.length>0?resolvedTranslation:resolvedTranslation.split(":::");var index=plurals_getTranslationIndex(locale,pluralization);return void 0===pluralizations[index]?(warnings&&console.warn("i18n: pluralization not provided in locale",translation,locale,index),pluralizations[0].trim()):pluralizations[index].trim()}};function isArray$1(obj){return!!obj&&Array===obj.constructor}return{store:i18nVuexModule,plugin:VuexI18nPlugin}});
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):(global=global||self).vuexI18n=factory()}(this,function(){"use strict";function _typeof(obj){return(_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})(obj)}var i18nVuexModule={namespaced:!0,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 obj,toReturn={};for(var i in translations)if(translations.hasOwnProperty(i)){var objType=_typeof(translations[i]);if((obj=translations[i])&&Array===obj.constructor){for(var count=translations[i].length,index=0;index<count;index++){if("string"!==_typeof(translations[i][index])){console.warn("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};var 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={install:function(Vue,store,config){"string"!=typeof arguments[2]&&"string"!=typeof arguments[3]||(console.warn("i18n: Registering the plugin vuex-i18n 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 moduleName=(config=Object.assign({warnings:!0,moduleName:"i18n",identifiers:["{","}"],preserveState:!1,translateFilterName:"translate",translateInFilterName:"translateIn",onTranslationNotFound:function(){}},config)).moduleName,identifiers=config.identifiers,translateFilterName=config.translateFilterName,translateInFilterName=config.translateInFilterName,onTranslationNotFound=config.onTranslationNotFound;if("function"!=typeof onTranslationNotFound&&(console.error("i18n: i18n config option onTranslationNotFound must be a function"),onTranslationNotFound=function(){}),store.registerModule(moduleName,i18nVuexModule,{preserveState:config.preserveState}),!1===store.state.hasOwnProperty(moduleName))return console.error("i18n: 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: i18n vuex module is not correctly initialized")});var render=renderFn(identifiers,config.warnings),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 config.warnings&&console.warn("i18n: 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;if(!1===translations.hasOwnProperty(locale)?translationExists=!1:!1===translations[locale].hasOwnProperty(key)&&(translationExists=!1),!0===translationExists)return render(locale,translations[locale][key],options,pluralization);if(localeRegional.length>1&&!0===translations.hasOwnProperty(localeRegional[0])&&!0===translations[localeRegional[0]].hasOwnProperty(key))return render(localeRegional[0],translations[localeRegional[0]][key],options,pluralization);var asyncTranslation=onTranslationNotFound(locale,key,defaultValue);return asyncTranslation&&Promise.resolve(asyncTranslation).then(function(value){var additionalTranslations={};additionalTranslations[key]=value,addLocale(locale,additionalTranslations)}),!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 scope=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"fallback",locale=store.state[moduleName].locale,fallback=store.state[moduleName].fallback,translations=store.state[moduleName].translations;if(translations.hasOwnProperty(locale)&&translations[locale].hasOwnProperty(key))return!0;if("strict"==scope)return!1;var localeRegional=locale.split("-");return!!(localeRegional.length>1&&translations.hasOwnProperty(localeRegional[0])&&translations[localeRegional[0]].hasOwnProperty(key))||"locale"!=scope&&!(!translations.hasOwnProperty(fallback)||!translations[fallback].hasOwnProperty(key))},setFallbackLocale=function(locale){store.dispatch({type:"".concat(moduleName,"/setFallbackLocale"),locale:locale})},setLocale=function(locale){store.dispatch({type:"".concat(moduleName,"/setLocale"),locale:locale})},getLocale=function(){return store.state[moduleName].locale},getLocales=function(){return Object.keys(store.state[moduleName].translations)},addLocale=function(locale,translations){return store.dispatch({type:"".concat(moduleName,"/addLocale"),locale:locale,translations:translations})},replaceLocale=function(locale,translations){return store.dispatch({type:"".concat(moduleName,"/replaceLocale"),locale:locale,translations:translations})},removeLocale=function(locale){store.state[moduleName].translations.hasOwnProperty(locale)&&store.dispatch({type:"".concat(moduleName,"/removeLocale"),locale:locale})},phaseOutExistsFn=function(locale){return config.warnings&&console.warn("i18n: $i18n.exists is depreceated. Please use $i18n.localeExists instead. It provides exactly the same functionality."),checkLocaleExists(locale)},checkLocaleExists=function(locale){return store.state[moduleName].translations.hasOwnProperty(locale)};Vue.prototype.$i18n={locale:getLocale,locales:getLocales,set:setLocale,add:addLocale,replace:replaceLocale,remove:removeLocale,fallback:setFallbackLocale,localeExists:checkLocaleExists,keyExists:checkKeyExists,translate:translate,translateIn:translateInLanguage,exists:phaseOutExistsFn},Vue.i18n={locale:getLocale,locales:getLocales,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(translateFilterName,translate),Vue.filter(translateInFilterName,function(key,locale){for(var _len=arguments.length,args=new Array(_len>2?_len-2:0),_key=2;_key<_len;_key++)args[_key-2]=arguments[_key];return translateInLanguage.apply(void 0,[locale,key].concat(args))})}},renderFn=function(identifiers){var warnings=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];null!=identifiers&&2==identifiers.length||console.warn("i18n: You must specify the start and end character identifying variable substitutions");var matcher=new RegExp(identifiers[0]+"{1}(\\w{1}|\\w.+?)"+identifiers[1]+"{1}","g"),replace=function(translation,replacements){return translation.replace?translation.replace(matcher,function(placeholder){var key=placeholder.replace(identifiers[0],"").replace(identifiers[1],"");return void 0!==replacements[key]?replacements[key]:(warnings&&(console.group?console.group("i18n: Not all placeholders found"):console.warn("i18n: 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=_typeof(translation),pluralizationType=_typeof(pluralization),resolvePlaceholders=function(){return isArray$1(translation)?translation.map(function(item){return replace(item,replacements)}):"string"===objType?replace(translation,replacements):void 0};if(null===pluralization)return resolvePlaceholders();if("number"!==pluralizationType)return warnings&&console.warn("i18n: pluralization is not a number"),resolvePlaceholders();var resolvedTranslation=resolvePlaceholders(),pluralizations=null;pluralizations=isArray$1(resolvedTranslation)&&resolvedTranslation.length>0?resolvedTranslation:resolvedTranslation.split(":::");var index=plurals_getTranslationIndex(locale,pluralization);return void 0===pluralizations[index]?(warnings&&console.warn("i18n: pluralization not provided in locale",translation,locale,index),pluralizations[0].trim()):pluralizations[index].trim()}};function isArray$1(obj){return!!obj&&Array===obj.constructor}return{store:i18nVuexModule,plugin:VuexI18nPlugin}});

@@ -414,2 +414,3 @@ (function (global, factory) {

translateFilterName: 'translate',
translateInFilterName: 'translateIn',
onTranslationNotFound: function onTranslationNotFound() {}

@@ -420,3 +421,4 @@ }, config); // define module name and identifiers as constants to prevent any changes

var identifiers = config.identifiers;
var translateFilterName = config.translateFilterName; // initialize the onTranslationNotFound function and make sure it is actually
var translateFilterName = config.translateFilterName;
var translateInFilterName = config.translateInFilterName; // initialize the onTranslationNotFound function and make sure it is actually
// a function

@@ -562,2 +564,11 @@

return render(locale, translations[fallback][key], options, pluralization);
}; // add a filter function to translate in a given locale (i.e. {{ 'something' | translateIn('en') }})
var translateInLanguageFilter = function translateInLanguageFilter(key, locale) {
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
return translateInLanguage.apply(void 0, [locale, key].concat(args));
}; // check if the given key exists in the current locale

@@ -702,2 +713,3 @@

Vue.filter(translateFilterName, translate);
Vue.filter(translateInFilterName, translateInLanguageFilter);
}; // renderFn will initialize a function to render the variable substitutions in

@@ -704,0 +716,0 @@ // the translation string. identifiers specify the tags will be used to find

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

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

@@ -169,2 +169,3 @@ # vuex-i18n

- `translateFilterName` (default `translate`)
- `translateInFilterName` (default `translateIn`)
- `onTranslationNotFound` (default `function(){}`)

@@ -305,3 +306,4 @@ - `warnings`: default(`true`)

// translate the given key in a specific locale
// translate the given key in a specific locale, also available as filter
// i.e {{ 'message' | translateIn('en') }}
$tlang(), Vue.i18n.translateIn()

@@ -308,0 +310,0 @@

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