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.7 to 1.10.8

181

dist/vuex-i18n.cjs.js
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
/* vuex-i18n-store defines a vuex module to store locale translations. Make sure

@@ -15,3 +9,3 @@ ** to also include the file vuex-i18n.js to enable easy access to localized

// define a simple vuex module to handle locale translations
var i18nVuexModule = {
const i18nVuexModule = {
namespaced: true,

@@ -26,9 +20,8 @@ state: {

// set the current locale
SET_LOCALE: function SET_LOCALE(state, payload) {
SET_LOCALE(state, payload) {
state.locale = payload.locale;
},
// add a new locale
ADD_LOCALE: function ADD_LOCALE(state, payload) {
ADD_LOCALE(state, payload) {

@@ -40,3 +33,3 @@ // reduce the given translations to a single-depth tree

// get the existing translations
var existingTranslations = state.translations[payload.locale];
let existingTranslations = state.translations[payload.locale];
// merge the translations

@@ -57,5 +50,4 @@ state.translations[payload.locale] = Object.assign({}, existingTranslations, translations);

// replace existing locale information with new translations
REPLACE_LOCALE: function REPLACE_LOCALE(state, payload) {
REPLACE_LOCALE(state, payload) {

@@ -76,5 +68,4 @@ // reduce the given translations to a single-depth tree

// remove a locale from the store
REMOVE_LOCALE: function REMOVE_LOCALE(state, payload) {
REMOVE_LOCALE(state, payload) {

@@ -91,3 +82,3 @@ // check if the given locale is present in the state

// create a copy of the translations object
var translationCopy = Object.assign({}, state.translations);
let translationCopy = Object.assign({}, state.translations);

@@ -101,5 +92,7 @@ // remove the given locale

},
SET_FALLBACK_LOCALE: function SET_FALLBACK_LOCALE(state, payload) {
SET_FALLBACK_LOCALE(state, payload) {
state.fallback = payload.locale;
}
},

@@ -109,3 +102,3 @@ actions: {

// set the current locale
setLocale: function setLocale(context, payload) {
setLocale(context, payload) {
context.commit({

@@ -117,5 +110,4 @@ type: 'SET_LOCALE',

// add or extend a locale with translations
addLocale: function addLocale(context, payload) {
addLocale(context, payload) {
context.commit({

@@ -128,5 +120,4 @@ type: 'ADD_LOCALE',

// replace locale information
replaceLocale: function replaceLocale(context, payload) {
replaceLocale(context, payload) {
context.commit({

@@ -139,5 +130,4 @@ type: 'REPLACE_LOCALE',

// remove the given locale translations
removeLocale: function removeLocale(context, payload) {
removeLocale(context, payload) {
context.commit({

@@ -149,3 +139,4 @@ type: 'REMOVE_LOCALE',

},
setFallbackLocale: function setFallbackLocale(context, payload) {
setFallbackLocale(context, payload) {
context.commit({

@@ -156,2 +147,3 @@ type: 'SET_FALLBACK_LOCALE',

}
}

@@ -162,7 +154,7 @@ };

// single-depth object tree
var flattenTranslations = function flattenTranslations(translations) {
const flattenTranslations = function flattenTranslations(translations) {
var toReturn = {};
let toReturn = {};
for (var i in translations) {
for (let i in translations) {

@@ -175,3 +167,3 @@ // check if the property is present

// get the type of the property
var objType = _typeof(translations[i]);
let objType = typeof translations[i];

@@ -181,6 +173,6 @@ // allow unflattened array of strings

var count = translations[i].length;
let count = translations[i].length;
for (var index = 0; index < count; index++) {
var itemType = _typeof(translations[i][index]);
for (let index = 0; index < count; index++) {
let itemType = typeof translations[i][index];

@@ -196,5 +188,5 @@ if (itemType !== 'string') {

var flatObject = flattenTranslations(translations[i]);
let flatObject = flattenTranslations(translations[i]);
for (var x in flatObject) {
for (let x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;

@@ -217,3 +209,3 @@

var plurals = {
getTranslationIndex: function getTranslationIndex(languageCode, n) {
getTranslationIndex: function (languageCode, n) {
switch (languageCode) {

@@ -364,3 +356,3 @@ case 'ay': // Aymará

// initialize the plugin object
var VuexI18nPlugin = {};
let VuexI18nPlugin = {};

@@ -386,16 +378,16 @@ // internationalization plugin for vue js using vuex

translateFilterName: 'translate',
onTranslationNotFound: function onTranslationNotFound() {}
onTranslationNotFound: function () {}
}, config);
// define module name and identifiers as constants to prevent any changes
var moduleName = config.moduleName;
var identifiers = config.identifiers;
var translateFilterName = config.translateFilterName;
const moduleName = config.moduleName;
const identifiers = config.identifiers;
const translateFilterName = config.translateFilterName;
// initialize the onTranslationNotFound function and make sure it is actually
// a function
var onTranslationNotFound = config.onTranslationNotFound;
let onTranslationNotFound = config.onTranslationNotFound;
if (typeof onTranslationNotFound !== 'function') {
console.error('i18n: i18n config option onTranslationNotFound must be a function');
onTranslationNotFound = function onTranslationNotFound() {};
onTranslationNotFound = function () {};
}

@@ -427,12 +419,12 @@

// initialize the replacement function
var render = renderFn(identifiers, config.warnings);
let render = renderFn(identifiers, config.warnings);
// get localized string from store. note that we pass the arguments passed
// to the function directly to the translateInLanguage function
var translate = function $t() {
let translate = function $t() {
// get the current language from the store
var locale = store.state[moduleName].locale;
let locale = store.state[moduleName].locale;
return translateInLanguage.apply(undefined, [locale].concat(Array.prototype.slice.call(arguments)));
return translateInLanguage(locale, ...arguments);
};

@@ -445,14 +437,14 @@

// 2: locale, key, defaultValue, options, pluralization
var translateInLanguage = function translateInLanguage(locale) {
let translateInLanguage = function translateInLanguage(locale) {
// read the function arguments
var args = arguments;
let args = arguments;
// initialize options
var key = '';
var defaultValue = '';
var options = {};
var pluralization = null;
let key = '';
let defaultValue = '';
let options = {};
let pluralization = null;
var count = args.length;
let count = args.length;

@@ -495,13 +487,13 @@ // check if a default value was specified and fill options accordingly

// get the translations from the store
var translations = store.state[moduleName].translations;
let translations = store.state[moduleName].translations;
// get the last resort fallback from the store
var fallback = store.state[moduleName].fallback;
let fallback = store.state[moduleName].fallback;
// split locale by - to support partial fallback for regional locales
// like de-CH, en-UK
var localeRegional = locale.split('-');
let localeRegional = locale.split('-');
// flag for translation to exist or not
var translationExists = true;
let translationExists = true;

@@ -529,8 +521,8 @@ // check if the language exists in the store. return the key if not

// invoke a method if a translation is not found
var asyncTranslation = onTranslationNotFound(locale, key, defaultValue);
let asyncTranslation = onTranslationNotFound(locale, key, defaultValue);
// resolve async translations by updating the store
if (asyncTranslation) {
Promise.resolve(asyncTranslation).then(function (value) {
var additionalTranslations = {};
Promise.resolve(asyncTranslation).then(value => {
let additionalTranslations = {};
additionalTranslations[key] = value;

@@ -557,10 +549,8 @@ addLocale(locale, additionalTranslations);

// check if the given key exists in the current locale
var checkKeyExists = function checkKeyExists(key) {
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'fallback';
let checkKeyExists = function checkKeyExists(key, scope = 'fallback') {
// get the current language from the store
var locale = store.state[moduleName].locale;
var fallback = store.state[moduleName].fallback;
var translations = store.state[moduleName].translations;
let locale = store.state[moduleName].locale;
let fallback = store.state[moduleName].fallback;
let translations = store.state[moduleName].translations;

@@ -577,3 +567,3 @@ // check the current translation

// check any localized translations
var localeRegional = locale.split('-');
let localeRegional = locale.split('-');

@@ -598,5 +588,5 @@ if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) && translations[localeRegional[0]].hasOwnProperty(key)) {

// set fallback locale
var setFallbackLocale = function setFallbackLocale(locale) {
let setFallbackLocale = function setFallbackLocale(locale) {
store.dispatch({
type: moduleName + '/setFallbackLocale',
type: `${moduleName}/setFallbackLocale`,
locale: locale

@@ -607,5 +597,5 @@ });

// set the current locale
var setLocale = function setLocale(locale) {
let setLocale = function setLocale(locale) {
store.dispatch({
type: moduleName + '/setLocale',
type: `${moduleName}/setLocale`,
locale: locale

@@ -616,3 +606,3 @@ });

// get the current locale
var getLocale = function getLocale() {
let getLocale = function getLocale() {
return store.state[moduleName].locale;

@@ -622,3 +612,3 @@ };

// get all available locales
var getLocales = function getLocales() {
let getLocales = function getLocales() {
return Object.keys(store.state[moduleName].translations);

@@ -628,5 +618,5 @@ };

// add predefined translations to the store (keeping existing information)
var addLocale = function addLocale(locale, translations) {
let addLocale = function addLocale(locale, translations) {
return store.dispatch({
type: moduleName + '/addLocale',
type: `${moduleName}/addLocale`,
locale: locale,

@@ -638,5 +628,5 @@ translations: translations

// replace all locale information in the store
var replaceLocale = function replaceLocale(locale, translations) {
let replaceLocale = function replaceLocale(locale, translations) {
return store.dispatch({
type: moduleName + '/replaceLocale',
type: `${moduleName}/replaceLocale`,
locale: locale,

@@ -648,6 +638,6 @@ translations: translations

// remove the givne locale from the store
var removeLocale = function removeLocale(locale) {
let removeLocale = function removeLocale(locale) {
if (store.state[moduleName].translations.hasOwnProperty(locale)) {
store.dispatch({
type: moduleName + '/removeLocale',
type: `${moduleName}/removeLocale`,
locale: locale

@@ -659,3 +649,3 @@ });

// we are phasing out the exists function
var phaseOutExistsFn = function phaseOutExistsFn(locale) {
let phaseOutExistsFn = function phaseOutExistsFn(locale) {
if (config.warnings) console.warn('i18n: $i18n.exists is depreceated. Please use $i18n.localeExists instead. It provides exactly the same functionality.');

@@ -666,3 +656,3 @@ return checkLocaleExists(locale);

// check if the given locale is already loaded
var checkLocaleExists = function checkLocaleExists(locale) {
let checkLocaleExists = function checkLocaleExists(locale) {
return store.state[moduleName].translations.hasOwnProperty(locale);

@@ -721,6 +711,4 @@ };

// every render cycle.
var renderFn = function renderFn(identifiers) {
var warnings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
let renderFn = function (identifiers, warnings = true) {
if (identifiers == null || identifiers.length != 2) {

@@ -731,6 +719,6 @@ console.warn('i18n: You must specify the start and end character identifying variable substitutions');

// construct a regular expression ot find variable substitutions, i.e. {test}
var matcher = new RegExp('' + identifiers[0] + '{1}\\w.+?' + identifiers[1] + '{1}', 'g');
let matcher = new RegExp('' + identifiers[0] + '{1}(\\w{1}|\\w.+?)' + identifiers[1] + '{1}', 'g');
// define the replacement function
var replace = function replace(translation, replacements) {
let replace = function replace(translation, replacements) {

@@ -745,3 +733,3 @@ // check if the object has a replace property

// remove the identifiers (can be set on the module level)
var key = placeholder.replace(identifiers[0], '').replace(identifiers[1], '');
let key = placeholder.replace(identifiers[0], '').replace(identifiers[1], '');

@@ -769,11 +757,8 @@ if (replacements[key] !== undefined) {

// translations for rendering
var render = function render(locale, translation) {
var replacements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var pluralization = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
let render = function render(locale, translation, replacements = {}, pluralization = null) {
// get the type of the property
var objType = typeof translation === 'undefined' ? 'undefined' : _typeof(translation);
var pluralizationType = typeof pluralization === 'undefined' ? 'undefined' : _typeof(pluralization);
let objType = typeof translation;
let pluralizationType = typeof pluralization;
var resolvePlaceholders = function resolvePlaceholders() {
let resolvePlaceholders = function () {

@@ -783,3 +768,3 @@ if (isArray$1(translation)) {

// replace the placeholder elements in all sub-items
return translation.map(function (item) {
return translation.map(item => {
return replace(item, replacements, false);

@@ -806,6 +791,6 @@ });

// replace all placeholders
var resolvedTranslation = resolvePlaceholders();
let resolvedTranslation = resolvePlaceholders();
// initialize pluralizations
var pluralizations = null;
let pluralizations = null;

@@ -822,3 +807,3 @@ // if translations are already an array and have more than one entry,

// determine the pluralization version to use by locale
var index = plurals.getTranslationIndex(locale, pluralization);
let index = plurals.getTranslationIndex(locale, pluralization);

@@ -825,0 +810,0 @@ // check if the specified index is present in the pluralization

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

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
/* vuex-i18n-store defines a vuex module to store locale translations. Make sure

@@ -13,3 +7,3 @@ ** to also include the file vuex-i18n.js to enable easy access to localized

// define a simple vuex module to handle locale translations
var i18nVuexModule = {
const i18nVuexModule = {
namespaced: true,

@@ -24,9 +18,8 @@ state: {

// set the current locale
SET_LOCALE: function SET_LOCALE(state, payload) {
SET_LOCALE(state, payload) {
state.locale = payload.locale;
},
// add a new locale
ADD_LOCALE: function ADD_LOCALE(state, payload) {
ADD_LOCALE(state, payload) {

@@ -38,3 +31,3 @@ // reduce the given translations to a single-depth tree

// get the existing translations
var existingTranslations = state.translations[payload.locale];
let existingTranslations = state.translations[payload.locale];
// merge the translations

@@ -55,5 +48,4 @@ state.translations[payload.locale] = Object.assign({}, existingTranslations, translations);

// replace existing locale information with new translations
REPLACE_LOCALE: function REPLACE_LOCALE(state, payload) {
REPLACE_LOCALE(state, payload) {

@@ -74,5 +66,4 @@ // reduce the given translations to a single-depth tree

// remove a locale from the store
REMOVE_LOCALE: function REMOVE_LOCALE(state, payload) {
REMOVE_LOCALE(state, payload) {

@@ -89,3 +80,3 @@ // check if the given locale is present in the state

// create a copy of the translations object
var translationCopy = Object.assign({}, state.translations);
let translationCopy = Object.assign({}, state.translations);

@@ -99,5 +90,7 @@ // remove the given locale

},
SET_FALLBACK_LOCALE: function SET_FALLBACK_LOCALE(state, payload) {
SET_FALLBACK_LOCALE(state, payload) {
state.fallback = payload.locale;
}
},

@@ -107,3 +100,3 @@ actions: {

// set the current locale
setLocale: function setLocale(context, payload) {
setLocale(context, payload) {
context.commit({

@@ -115,5 +108,4 @@ type: 'SET_LOCALE',

// add or extend a locale with translations
addLocale: function addLocale(context, payload) {
addLocale(context, payload) {
context.commit({

@@ -126,5 +118,4 @@ type: 'ADD_LOCALE',

// replace locale information
replaceLocale: function replaceLocale(context, payload) {
replaceLocale(context, payload) {
context.commit({

@@ -137,5 +128,4 @@ type: 'REPLACE_LOCALE',

// remove the given locale translations
removeLocale: function removeLocale(context, payload) {
removeLocale(context, payload) {
context.commit({

@@ -147,3 +137,4 @@ type: 'REMOVE_LOCALE',

},
setFallbackLocale: function setFallbackLocale(context, payload) {
setFallbackLocale(context, payload) {
context.commit({

@@ -154,2 +145,3 @@ type: 'SET_FALLBACK_LOCALE',

}
}

@@ -160,7 +152,7 @@ };

// single-depth object tree
var flattenTranslations = function flattenTranslations(translations) {
const flattenTranslations = function flattenTranslations(translations) {
var toReturn = {};
let toReturn = {};
for (var i in translations) {
for (let i in translations) {

@@ -173,3 +165,3 @@ // check if the property is present

// get the type of the property
var objType = _typeof(translations[i]);
let objType = typeof translations[i];

@@ -179,6 +171,6 @@ // allow unflattened array of strings

var count = translations[i].length;
let count = translations[i].length;
for (var index = 0; index < count; index++) {
var itemType = _typeof(translations[i][index]);
for (let index = 0; index < count; index++) {
let itemType = typeof translations[i][index];

@@ -194,5 +186,5 @@ if (itemType !== 'string') {

var flatObject = flattenTranslations(translations[i]);
let flatObject = flattenTranslations(translations[i]);
for (var x in flatObject) {
for (let x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;

@@ -215,3 +207,3 @@

var plurals = {
getTranslationIndex: function getTranslationIndex(languageCode, n) {
getTranslationIndex: function (languageCode, n) {
switch (languageCode) {

@@ -362,3 +354,3 @@ case 'ay': // Aymará

// initialize the plugin object
var VuexI18nPlugin = {};
let VuexI18nPlugin = {};

@@ -384,16 +376,16 @@ // internationalization plugin for vue js using vuex

translateFilterName: 'translate',
onTranslationNotFound: function onTranslationNotFound() {}
onTranslationNotFound: function () {}
}, config);
// define module name and identifiers as constants to prevent any changes
var moduleName = config.moduleName;
var identifiers = config.identifiers;
var translateFilterName = config.translateFilterName;
const moduleName = config.moduleName;
const identifiers = config.identifiers;
const translateFilterName = config.translateFilterName;
// initialize the onTranslationNotFound function and make sure it is actually
// a function
var onTranslationNotFound = config.onTranslationNotFound;
let onTranslationNotFound = config.onTranslationNotFound;
if (typeof onTranslationNotFound !== 'function') {
console.error('i18n: i18n config option onTranslationNotFound must be a function');
onTranslationNotFound = function onTranslationNotFound() {};
onTranslationNotFound = function () {};
}

@@ -425,12 +417,12 @@

// initialize the replacement function
var render = renderFn(identifiers, config.warnings);
let render = renderFn(identifiers, config.warnings);
// get localized string from store. note that we pass the arguments passed
// to the function directly to the translateInLanguage function
var translate = function $t() {
let translate = function $t() {
// get the current language from the store
var locale = store.state[moduleName].locale;
let locale = store.state[moduleName].locale;
return translateInLanguage.apply(undefined, [locale].concat(Array.prototype.slice.call(arguments)));
return translateInLanguage(locale, ...arguments);
};

@@ -443,14 +435,14 @@

// 2: locale, key, defaultValue, options, pluralization
var translateInLanguage = function translateInLanguage(locale) {
let translateInLanguage = function translateInLanguage(locale) {
// read the function arguments
var args = arguments;
let args = arguments;
// initialize options
var key = '';
var defaultValue = '';
var options = {};
var pluralization = null;
let key = '';
let defaultValue = '';
let options = {};
let pluralization = null;
var count = args.length;
let count = args.length;

@@ -493,13 +485,13 @@ // check if a default value was specified and fill options accordingly

// get the translations from the store
var translations = store.state[moduleName].translations;
let translations = store.state[moduleName].translations;
// get the last resort fallback from the store
var fallback = store.state[moduleName].fallback;
let fallback = store.state[moduleName].fallback;
// split locale by - to support partial fallback for regional locales
// like de-CH, en-UK
var localeRegional = locale.split('-');
let localeRegional = locale.split('-');
// flag for translation to exist or not
var translationExists = true;
let translationExists = true;

@@ -527,8 +519,8 @@ // check if the language exists in the store. return the key if not

// invoke a method if a translation is not found
var asyncTranslation = onTranslationNotFound(locale, key, defaultValue);
let asyncTranslation = onTranslationNotFound(locale, key, defaultValue);
// resolve async translations by updating the store
if (asyncTranslation) {
Promise.resolve(asyncTranslation).then(function (value) {
var additionalTranslations = {};
Promise.resolve(asyncTranslation).then(value => {
let additionalTranslations = {};
additionalTranslations[key] = value;

@@ -555,10 +547,8 @@ addLocale(locale, additionalTranslations);

// check if the given key exists in the current locale
var checkKeyExists = function checkKeyExists(key) {
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'fallback';
let checkKeyExists = function checkKeyExists(key, scope = 'fallback') {
// get the current language from the store
var locale = store.state[moduleName].locale;
var fallback = store.state[moduleName].fallback;
var translations = store.state[moduleName].translations;
let locale = store.state[moduleName].locale;
let fallback = store.state[moduleName].fallback;
let translations = store.state[moduleName].translations;

@@ -575,3 +565,3 @@ // check the current translation

// check any localized translations
var localeRegional = locale.split('-');
let localeRegional = locale.split('-');

@@ -596,5 +586,5 @@ if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) && translations[localeRegional[0]].hasOwnProperty(key)) {

// set fallback locale
var setFallbackLocale = function setFallbackLocale(locale) {
let setFallbackLocale = function setFallbackLocale(locale) {
store.dispatch({
type: moduleName + '/setFallbackLocale',
type: `${moduleName}/setFallbackLocale`,
locale: locale

@@ -605,5 +595,5 @@ });

// set the current locale
var setLocale = function setLocale(locale) {
let setLocale = function setLocale(locale) {
store.dispatch({
type: moduleName + '/setLocale',
type: `${moduleName}/setLocale`,
locale: locale

@@ -614,3 +604,3 @@ });

// get the current locale
var getLocale = function getLocale() {
let getLocale = function getLocale() {
return store.state[moduleName].locale;

@@ -620,3 +610,3 @@ };

// get all available locales
var getLocales = function getLocales() {
let getLocales = function getLocales() {
return Object.keys(store.state[moduleName].translations);

@@ -626,5 +616,5 @@ };

// add predefined translations to the store (keeping existing information)
var addLocale = function addLocale(locale, translations) {
let addLocale = function addLocale(locale, translations) {
return store.dispatch({
type: moduleName + '/addLocale',
type: `${moduleName}/addLocale`,
locale: locale,

@@ -636,5 +626,5 @@ translations: translations

// replace all locale information in the store
var replaceLocale = function replaceLocale(locale, translations) {
let replaceLocale = function replaceLocale(locale, translations) {
return store.dispatch({
type: moduleName + '/replaceLocale',
type: `${moduleName}/replaceLocale`,
locale: locale,

@@ -646,6 +636,6 @@ translations: translations

// remove the givne locale from the store
var removeLocale = function removeLocale(locale) {
let removeLocale = function removeLocale(locale) {
if (store.state[moduleName].translations.hasOwnProperty(locale)) {
store.dispatch({
type: moduleName + '/removeLocale',
type: `${moduleName}/removeLocale`,
locale: locale

@@ -657,3 +647,3 @@ });

// we are phasing out the exists function
var phaseOutExistsFn = function phaseOutExistsFn(locale) {
let phaseOutExistsFn = function phaseOutExistsFn(locale) {
if (config.warnings) console.warn('i18n: $i18n.exists is depreceated. Please use $i18n.localeExists instead. It provides exactly the same functionality.');

@@ -664,3 +654,3 @@ return checkLocaleExists(locale);

// check if the given locale is already loaded
var checkLocaleExists = function checkLocaleExists(locale) {
let checkLocaleExists = function checkLocaleExists(locale) {
return store.state[moduleName].translations.hasOwnProperty(locale);

@@ -719,6 +709,4 @@ };

// every render cycle.
var renderFn = function renderFn(identifiers) {
var warnings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
let renderFn = function (identifiers, warnings = true) {
if (identifiers == null || identifiers.length != 2) {

@@ -729,6 +717,6 @@ console.warn('i18n: You must specify the start and end character identifying variable substitutions');

// construct a regular expression ot find variable substitutions, i.e. {test}
var matcher = new RegExp('' + identifiers[0] + '{1}\\w.+?' + identifiers[1] + '{1}', 'g');
let matcher = new RegExp('' + identifiers[0] + '{1}(\\w{1}|\\w.+?)' + identifiers[1] + '{1}', 'g');
// define the replacement function
var replace = function replace(translation, replacements) {
let replace = function replace(translation, replacements) {

@@ -743,3 +731,3 @@ // check if the object has a replace property

// remove the identifiers (can be set on the module level)
var key = placeholder.replace(identifiers[0], '').replace(identifiers[1], '');
let key = placeholder.replace(identifiers[0], '').replace(identifiers[1], '');

@@ -767,11 +755,8 @@ if (replacements[key] !== undefined) {

// translations for rendering
var render = function render(locale, translation) {
var replacements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var pluralization = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
let render = function render(locale, translation, replacements = {}, pluralization = null) {
// get the type of the property
var objType = typeof translation === 'undefined' ? 'undefined' : _typeof(translation);
var pluralizationType = typeof pluralization === 'undefined' ? 'undefined' : _typeof(pluralization);
let objType = typeof translation;
let pluralizationType = typeof pluralization;
var resolvePlaceholders = function resolvePlaceholders() {
let resolvePlaceholders = function () {

@@ -781,3 +766,3 @@ if (isArray$1(translation)) {

// replace the placeholder elements in all sub-items
return translation.map(function (item) {
return translation.map(item => {
return replace(item, replacements, false);

@@ -804,6 +789,6 @@ });

// replace all placeholders
var resolvedTranslation = resolvePlaceholders();
let resolvedTranslation = resolvePlaceholders();
// initialize pluralizations
var pluralizations = null;
let pluralizations = null;

@@ -820,3 +805,3 @@ // if translations are already an array and have more than one entry,

// determine the pluralization version to use by locale
var index = plurals.getTranslationIndex(locale, pluralization);
let index = plurals.getTranslationIndex(locale, pluralization);

@@ -823,0 +808,0 @@ // check if the specified index is present in the pluralization

@@ -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={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 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("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("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:moduleName+"/setFallbackLocale",locale:locale})},setLocale=function(locale){store.dispatch({type: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:moduleName+"/addLocale",locale:locale,translations:translations})},replaceLocale=function(locale,translations){return store.dispatch({type:moduleName+"/replaceLocale",locale:locale,translations:translations})},removeLocale=function(locale){store.state[moduleName].translations.hasOwnProperty(locale)&&store.dispatch({type: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)};var 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.+?"+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=void 0===translation?"undefined":_typeof(translation),pluralizationType=void 0===pluralization?"undefined":_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()}};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.vuexI18n=factory()}(this,function(){"use strict";const i18nVuexModule={namespaced:!0,state:{locale:null,fallback:null,translations:{}},mutations:{SET_LOCALE(state,payload){state.locale=payload.locale},ADD_LOCALE(state,payload){var translations=flattenTranslations(payload.translations);if(state.translations.hasOwnProperty(payload.locale)){let 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(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(state,payload){if(state.translations.hasOwnProperty(payload.locale)){state.locale===payload.locale&&(state.locale=null);let translationCopy=Object.assign({},state.translations);delete translationCopy[payload.locale],state.translations=translationCopy}},SET_FALLBACK_LOCALE(state,payload){state.fallback=payload.locale}},actions:{setLocale(context,payload){context.commit({type:"SET_LOCALE",locale:payload.locale})},addLocale(context,payload){context.commit({type:"ADD_LOCALE",locale:payload.locale,translations:payload.translations})},replaceLocale(context,payload){context.commit({type:"REPLACE_LOCALE",locale:payload.locale,translations:payload.translations})},removeLocale(context,payload){context.commit({type:"REMOVE_LOCALE",locale:payload.locale,translations:payload.translations})},setFallbackLocale(context,payload){context.commit({type:"SET_FALLBACK_LOCALE",locale:payload.locale})}}},flattenTranslations=function flattenTranslations(translations){let toReturn={};for(let i in translations){if(!translations.hasOwnProperty(i))continue;let objType=typeof translations[i];if((obj=translations[i])&&Array===obj.constructor){let count=translations[i].length;for(let 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){let flatObject=flattenTranslations(translations[i]);for(let x in flatObject)flatObject.hasOwnProperty(x)&&(toReturn[i+"."+x]=flatObject[x])}else toReturn[i]=translations[i]}var obj;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}};let 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]});const moduleName=(config=Object.assign({warnings:!0,moduleName:"i18n",identifiers:["{","}"],preserveState:!1,translateFilterName:"translate",onTranslationNotFound:function(){}},config)).moduleName,identifiers=config.identifiers,translateFilterName=config.translateFilterName;let 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")});let render=renderFn(identifiers,config.warnings),translate=function(){let locale=store.state[moduleName].locale;return translateInLanguage(locale,...arguments)},translateInLanguage=function(locale){let 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;let 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);let asyncTranslation=onTranslationNotFound(locale,key,defaultValue);return asyncTranslation&&Promise.resolve(asyncTranslation).then(value=>{let 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,scope="fallback"){let 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;let 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:`${moduleName}/setFallbackLocale`,locale:locale})},setLocale=function(locale){store.dispatch({type:`${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:`${moduleName}/addLocale`,locale:locale,translations:translations})},replaceLocale=function(locale,translations){return store.dispatch({type:`${moduleName}/replaceLocale`,locale:locale,translations:translations})},removeLocale=function(locale){store.state[moduleName].translations.hasOwnProperty(locale)&&store.dispatch({type:`${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,warnings=!0){null!=identifiers&&2==identifiers.length||console.warn("i18n: You must specify the start and end character identifying variable substitutions");let 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){let 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,replacements={},pluralization=null){let objType=typeof translation,pluralizationType=typeof pluralization,resolvePlaceholders=function(){return isArray$1(translation)?translation.map(item=>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();let resolvedTranslation=resolvePlaceholders(),pluralizations=null;pluralizations=isArray$1(resolvedTranslation)&&resolvedTranslation.length>0?resolvedTranslation:resolvedTranslation.split(":::");let 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) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.vuexI18n = factory());
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.vuexI18n = factory());
}(this, (function () { 'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
/* vuex-i18n-store defines a vuex module to store locale translations. Make sure
** to also include the file vuex-i18n.js to enable easy access to localized
** strings in your vue components.
*/
/* vuex-i18n-store defines a vuex module to store locale translations. Make sure
** to also include the file vuex-i18n.js to enable easy access to localized
** strings in your vue components.
*/
// define a simple vuex module to handle locale translations
const i18nVuexModule = {
namespaced: true,
state: {
locale: null,
fallback: null,
translations: {}
},
mutations: {
// define a simple vuex module to handle locale translations
var i18nVuexModule = {
namespaced: true,
state: {
locale: null,
fallback: null,
translations: {}
},
mutations: {
// set the current locale
SET_LOCALE(state, payload) {
state.locale = payload.locale;
},
// set the current locale
SET_LOCALE: function SET_LOCALE(state, payload) {
state.locale = payload.locale;
},
// add a new locale
ADD_LOCALE(state, payload) {
// reduce the given translations to a single-depth tree
var translations = flattenTranslations(payload.translations);
// add a new locale
ADD_LOCALE: function ADD_LOCALE(state, payload) {
if (state.translations.hasOwnProperty(payload.locale)) {
// get the existing translations
let existingTranslations = state.translations[payload.locale];
// merge the translations
state.translations[payload.locale] = Object.assign({}, existingTranslations, translations);
} else {
// just set the locale if it does not yet exist
state.translations[payload.locale] = translations;
}
// reduce the given translations to a single-depth tree
var translations = flattenTranslations(payload.translations);
// make sure to notify vue of changes (this might break with new vue versions)
try {
if (state.translations.__ob__) {
state.translations.__ob__.dep.notify();
}
} catch (ex) {}
},
if (state.translations.hasOwnProperty(payload.locale)) {
// get the existing translations
var existingTranslations = state.translations[payload.locale];
// merge the translations
state.translations[payload.locale] = Object.assign({}, existingTranslations, translations);
} else {
// just set the locale if it does not yet exist
state.translations[payload.locale] = translations;
}
// replace existing locale information with new translations
REPLACE_LOCALE(state, payload) {
// make sure to notify vue of changes (this might break with new vue versions)
try {
if (state.translations.__ob__) {
state.translations.__ob__.dep.notify();
}
} catch (ex) {}
},
// reduce the given translations to a single-depth tree
var translations = flattenTranslations(payload.translations);
// replace the translations entirely
state.translations[payload.locale] = translations;
// replace existing locale information with new translations
REPLACE_LOCALE: function REPLACE_LOCALE(state, payload) {
// make sure to notify vue of changes (this might break with new vue versions)
try {
if (state.translations.__ob__) {
state.translations.__ob__.dep.notify();
}
} catch (ex) {}
},
// reduce the given translations to a single-depth tree
var translations = flattenTranslations(payload.translations);
// remove a locale from the store
REMOVE_LOCALE(state, payload) {
// replace the translations entirely
state.translations[payload.locale] = translations;
// check if the given locale is present in the state
if (state.translations.hasOwnProperty(payload.locale)) {
// make sure to notify vue of changes (this might break with new vue versions)
try {
if (state.translations.__ob__) {
state.translations.__ob__.dep.notify();
}
} catch (ex) {}
},
// check if the current locale is the given locale to remvoe
if (state.locale === payload.locale) {
// reset the current locale
state.locale = null;
}
// create a copy of the translations object
let translationCopy = Object.assign({}, state.translations);
// remove a locale from the store
REMOVE_LOCALE: function REMOVE_LOCALE(state, payload) {
// remove the given locale
delete translationCopy[payload.locale];
// check if the given locale is present in the state
if (state.translations.hasOwnProperty(payload.locale)) {
// set the state to the new object
state.translations = translationCopy;
}
},
// check if the current locale is the given locale to remvoe
if (state.locale === payload.locale) {
// reset the current locale
state.locale = null;
}
SET_FALLBACK_LOCALE(state, payload) {
state.fallback = payload.locale;
}
// create a copy of the translations object
var translationCopy = Object.assign({}, state.translations);
},
actions: {
// remove the given locale
delete translationCopy[payload.locale];
// set the current locale
setLocale(context, payload) {
context.commit({
type: 'SET_LOCALE',
locale: payload.locale
});
},
// set the state to the new object
state.translations = translationCopy;
}
},
SET_FALLBACK_LOCALE: function SET_FALLBACK_LOCALE(state, payload) {
state.fallback = payload.locale;
}
},
actions: {
// add or extend a locale with translations
addLocale(context, payload) {
context.commit({
type: 'ADD_LOCALE',
locale: payload.locale,
translations: payload.translations
});
},
// set the current locale
setLocale: function setLocale(context, payload) {
context.commit({
type: 'SET_LOCALE',
locale: payload.locale
});
},
// replace locale information
replaceLocale(context, payload) {
context.commit({
type: 'REPLACE_LOCALE',
locale: payload.locale,
translations: payload.translations
});
},
// remove the given locale translations
removeLocale(context, payload) {
context.commit({
type: 'REMOVE_LOCALE',
locale: payload.locale,
translations: payload.translations
});
},
// add or extend a locale with translations
addLocale: function addLocale(context, payload) {
context.commit({
type: 'ADD_LOCALE',
locale: payload.locale,
translations: payload.translations
});
},
setFallbackLocale(context, payload) {
context.commit({
type: 'SET_FALLBACK_LOCALE',
locale: payload.locale
});
}
}
};
// replace locale information
replaceLocale: function replaceLocale(context, payload) {
context.commit({
type: 'REPLACE_LOCALE',
locale: payload.locale,
translations: payload.translations
});
},
// flattenTranslations will convert object trees for translations into a
// single-depth object tree
const flattenTranslations = function flattenTranslations(translations) {
let toReturn = {};
// remove the given locale translations
removeLocale: function removeLocale(context, payload) {
context.commit({
type: 'REMOVE_LOCALE',
locale: payload.locale,
translations: payload.translations
});
},
setFallbackLocale: function setFallbackLocale(context, payload) {
context.commit({
type: 'SET_FALLBACK_LOCALE',
locale: payload.locale
});
}
}
};
for (let i in translations) {
// flattenTranslations will convert object trees for translations into a
// single-depth object tree
var flattenTranslations = function flattenTranslations(translations) {
// check if the property is present
if (!translations.hasOwnProperty(i)) {
continue;
}
var toReturn = {};
// get the type of the property
let objType = typeof translations[i];
for (var i in translations) {
// allow unflattened array of strings
if (isArray(translations[i])) {
// check if the property is present
if (!translations.hasOwnProperty(i)) {
continue;
}
let count = translations[i].length;
// get the type of the property
var objType = _typeof(translations[i]);
for (let index = 0; index < count; index++) {
let itemType = typeof translations[i][index];
// allow unflattened array of strings
if (isArray(translations[i])) {
if (itemType !== 'string') {
console.warn('i18n:', 'currently only arrays of strings are fully supported', translations[i]);
break;
}
}
var count = translations[i].length;
toReturn[i] = translations[i];
} else if (objType == 'object' && objType !== null) {
for (var index = 0; index < count; index++) {
var itemType = _typeof(translations[i][index]);
let flatObject = flattenTranslations(translations[i]);
if (itemType !== 'string') {
console.warn('i18n:', 'currently only arrays of strings are fully supported', translations[i]);
break;
}
}
for (let x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i] = translations[i];
} else if (objType == 'object' && objType !== null) {
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = translations[i];
}
}
return toReturn;
};
var flatObject = flattenTranslations(translations[i]);
// check if the given object is an array
function isArray(obj) {
return !!obj && Array === obj.constructor;
}
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
var plurals = {
getTranslationIndex: function (languageCode, n) {
switch (languageCode) {
case 'ay': // Aymará
case 'bo': // Tibetan
case 'cgg': // Chiga
case 'dz': // Dzongkha
case 'fa': // Persian
case 'id': // Indonesian
case 'ja': // Japanese
case 'jbo': // Lojban
case 'ka': // Georgian
case 'kk': // Kazakh
case 'km': // Khmer
case 'ko': // Korean
case 'ky': // Kyrgyz
case 'lo': // Lao
case 'ms': // Malay
case 'my': // Burmese
case 'sah': // Yakut
case 'su': // Sundanese
case 'th': // Thai
case 'tt': // Tatar
case 'ug': // Uyghur
case 'vi': // Vietnamese
case 'wo': // Wolof
case 'zh':
// Chinese
// 1 form
return 0;
case 'is':
// Icelandic
// 2 forms
return n % 10 !== 1 || n % 100 === 11 ? 1 : 0;
case 'jv':
// Javanese
// 2 forms
return n !== 0 ? 1 : 0;
case 'mk':
// Macedonian
// 2 forms
return n === 1 || n % 10 === 1 ? 0 : 1;
case 'ach': // Acholi
case 'ak': // Akan
case 'am': // Amharic
case 'arn': // Mapudungun
case 'br': // Breton
case 'fil': // Filipino
case 'fr': // French
case 'gun': // Gun
case 'ln': // Lingala
case 'mfe': // Mauritian Creole
case 'mg': // Malagasy
case 'mi': // Maori
case 'oc': // Occitan
case 'pt_BR': // Brazilian Portuguese
case 'tg': // Tajik
case 'ti': // Tigrinya
case 'tr': // Turkish
case 'uz': // Uzbek
case 'wa': // Walloon
/* eslint-disable */
/* Disable "Duplicate case label" because there are 2 forms of Chinese plurals */
case 'zh':
// Chinese
/* eslint-enable */
// 2 forms
return n > 1 ? 1 : 0;
case 'lv':
// Latvian
// 3 forms
return n % 10 === 1 && n % 100 !== 11 ? 0 : n !== 0 ? 1 : 2;
case 'lt':
// Lithuanian
// 3 forms
return n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
case 'be': // Belarusian
case 'bs': // Bosnian
case 'hr': // Croatian
case 'ru': // Russian
case 'sr': // Serbian
case 'uk':
// Ukrainian
// 3 forms
return n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
case 'mnk':
// Mandinka
// 3 forms
return n === 0 ? 0 : n === 1 ? 1 : 2;
case 'ro':
// Romanian
// 3 forms
return n === 1 ? 0 : n === 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2;
case 'pl':
// Polish
// 3 forms
return n === 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
case 'cs': // Czech
case 'sk':
// Slovak
// 3 forms
return n === 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2;
case 'csb':
// Kashubian
// 3 forms
return n === 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
case 'sl':
// Slovenian
// 4 forms
return n % 100 === 1 ? 0 : n % 100 === 2 ? 1 : n % 100 === 3 || n % 100 === 4 ? 2 : 3;
case 'mt':
// Maltese
// 4 forms
return n === 1 ? 0 : n === 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3;
case 'gd':
// Scottish Gaelic
// 4 forms
return n === 1 || n === 11 ? 0 : n === 2 || n === 12 ? 1 : n > 2 && n < 20 ? 2 : 3;
case 'cy':
// Welsh
// 4 forms
return n === 1 ? 0 : n === 2 ? 1 : n !== 8 && n !== 11 ? 2 : 3;
case 'kw':
// Cornish
// 4 forms
return n === 1 ? 0 : n === 2 ? 1 : n === 3 ? 2 : 3;
case 'ga':
// Irish
// 5 forms
return n === 1 ? 0 : n === 2 ? 1 : n > 2 && n < 7 ? 2 : n > 6 && n < 11 ? 3 : 4;
case 'ar':
// Arabic
// 6 forms
return n === 0 ? 0 : n === 1 ? 1 : n === 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5;
default:
// Everything else
return n !== 1 ? 1 : 0;
}
}
};
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = translations[i];
}
}
return toReturn;
};
/* vuex-i18n defines the Vuexi18nPlugin to enable localization using a vuex
** module to store the translation information. Make sure to also include the
** file vuex-i18n-store.js to include a respective vuex module.
*/
// check if the given object is an array
function isArray(obj) {
return !!obj && Array === obj.constructor;
}
// initialize the plugin object
let VuexI18nPlugin = {};
var plurals = {
getTranslationIndex: function getTranslationIndex(languageCode, n) {
switch (languageCode) {
case 'ay': // Aymará
case 'bo': // Tibetan
case 'cgg': // Chiga
case 'dz': // Dzongkha
case 'fa': // Persian
case 'id': // Indonesian
case 'ja': // Japanese
case 'jbo': // Lojban
case 'ka': // Georgian
case 'kk': // Kazakh
case 'km': // Khmer
case 'ko': // Korean
case 'ky': // Kyrgyz
case 'lo': // Lao
case 'ms': // Malay
case 'my': // Burmese
case 'sah': // Yakut
case 'su': // Sundanese
case 'th': // Thai
case 'tt': // Tatar
case 'ug': // Uyghur
case 'vi': // Vietnamese
case 'wo': // Wolof
case 'zh':
// Chinese
// 1 form
return 0;
case 'is':
// Icelandic
// 2 forms
return n % 10 !== 1 || n % 100 === 11 ? 1 : 0;
case 'jv':
// Javanese
// 2 forms
return n !== 0 ? 1 : 0;
case 'mk':
// Macedonian
// 2 forms
return n === 1 || n % 10 === 1 ? 0 : 1;
case 'ach': // Acholi
case 'ak': // Akan
case 'am': // Amharic
case 'arn': // Mapudungun
case 'br': // Breton
case 'fil': // Filipino
case 'fr': // French
case 'gun': // Gun
case 'ln': // Lingala
case 'mfe': // Mauritian Creole
case 'mg': // Malagasy
case 'mi': // Maori
case 'oc': // Occitan
case 'pt_BR': // Brazilian Portuguese
case 'tg': // Tajik
case 'ti': // Tigrinya
case 'tr': // Turkish
case 'uz': // Uzbek
case 'wa': // Walloon
/* eslint-disable */
/* Disable "Duplicate case label" because there are 2 forms of Chinese plurals */
case 'zh':
// Chinese
/* eslint-enable */
// 2 forms
return n > 1 ? 1 : 0;
case 'lv':
// Latvian
// 3 forms
return n % 10 === 1 && n % 100 !== 11 ? 0 : n !== 0 ? 1 : 2;
case 'lt':
// Lithuanian
// 3 forms
return n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
case 'be': // Belarusian
case 'bs': // Bosnian
case 'hr': // Croatian
case 'ru': // Russian
case 'sr': // Serbian
case 'uk':
// Ukrainian
// 3 forms
return n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
case 'mnk':
// Mandinka
// 3 forms
return n === 0 ? 0 : n === 1 ? 1 : 2;
case 'ro':
// Romanian
// 3 forms
return n === 1 ? 0 : n === 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2;
case 'pl':
// Polish
// 3 forms
return n === 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
case 'cs': // Czech
case 'sk':
// Slovak
// 3 forms
return n === 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2;
case 'csb':
// Kashubian
// 3 forms
return n === 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
case 'sl':
// Slovenian
// 4 forms
return n % 100 === 1 ? 0 : n % 100 === 2 ? 1 : n % 100 === 3 || n % 100 === 4 ? 2 : 3;
case 'mt':
// Maltese
// 4 forms
return n === 1 ? 0 : n === 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3;
case 'gd':
// Scottish Gaelic
// 4 forms
return n === 1 || n === 11 ? 0 : n === 2 || n === 12 ? 1 : n > 2 && n < 20 ? 2 : 3;
case 'cy':
// Welsh
// 4 forms
return n === 1 ? 0 : n === 2 ? 1 : n !== 8 && n !== 11 ? 2 : 3;
case 'kw':
// Cornish
// 4 forms
return n === 1 ? 0 : n === 2 ? 1 : n === 3 ? 2 : 3;
case 'ga':
// Irish
// 5 forms
return n === 1 ? 0 : n === 2 ? 1 : n > 2 && n < 7 ? 2 : n > 6 && n < 11 ? 3 : 4;
case 'ar':
// Arabic
// 6 forms
return n === 0 ? 0 : n === 1 ? 1 : n === 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5;
default:
// Everything else
return n !== 1 ? 1 : 0;
}
}
};
// internationalization plugin for vue js using vuex
VuexI18nPlugin.install = function install(Vue, store, config) {
/* vuex-i18n defines the Vuexi18nPlugin to enable localization using a vuex
** module to store the translation information. Make sure to also include the
** file vuex-i18n-store.js to include a respective vuex module.
*/
// TODO: remove this block for next major update (API break)
if (typeof arguments[2] === 'string' || typeof arguments[3] === 'string') {
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]
};
}
// initialize the plugin object
var VuexI18nPlugin = {};
// merge default options with user supplied options
config = Object.assign({
warnings: true,
moduleName: 'i18n',
identifiers: ['{', '}'],
preserveState: false,
translateFilterName: 'translate',
onTranslationNotFound: function () {}
}, config);
// internationalization plugin for vue js using vuex
VuexI18nPlugin.install = function install(Vue, store, config) {
// define module name and identifiers as constants to prevent any changes
const moduleName = config.moduleName;
const identifiers = config.identifiers;
const translateFilterName = config.translateFilterName;
// TODO: remove this block for next major update (API break)
if (typeof arguments[2] === 'string' || typeof arguments[3] === 'string') {
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]
};
}
// initialize the onTranslationNotFound function and make sure it is actually
// a function
let onTranslationNotFound = config.onTranslationNotFound;
if (typeof onTranslationNotFound !== 'function') {
console.error('i18n: i18n config option onTranslationNotFound must be a function');
onTranslationNotFound = function () {};
}
// merge default options with user supplied options
config = Object.assign({
warnings: true,
moduleName: 'i18n',
identifiers: ['{', '}'],
preserveState: false,
translateFilterName: 'translate',
onTranslationNotFound: function onTranslationNotFound() {}
}, config);
// register the i18n module in the vuex store
// preserveState can be used via configuration if server side rendering is used
store.registerModule(moduleName, i18nVuexModule, { preserveState: config.preserveState });
// define module name and identifiers as constants to prevent any changes
var moduleName = config.moduleName;
var identifiers = config.identifiers;
var translateFilterName = config.translateFilterName;
// check if the plugin was correctly initialized
if (store.state.hasOwnProperty(moduleName) === false) {
console.error('i18n: i18n vuex module is not correctly initialized. Please check the module name:', moduleName);
// initialize the onTranslationNotFound function and make sure it is actually
// a function
var onTranslationNotFound = config.onTranslationNotFound;
if (typeof onTranslationNotFound !== 'function') {
console.error('i18n: i18n config option onTranslationNotFound must be a function');
onTranslationNotFound = function onTranslationNotFound() {};
}
// always return the key if module is not initialized correctly
Vue.prototype.$i18n = function (key) {
return key;
};
// register the i18n module in the vuex store
// preserveState can be used via configuration if server side rendering is used
store.registerModule(moduleName, i18nVuexModule, { preserveState: config.preserveState });
Vue.prototype.$getLanguage = function () {
return null;
};
// check if the plugin was correctly initialized
if (store.state.hasOwnProperty(moduleName) === false) {
console.error('i18n: i18n vuex module is not correctly initialized. Please check the module name:', moduleName);
Vue.prototype.$setLanguage = function () {
console.error('i18n: i18n vuex module is not correctly initialized');
};
// always return the key if module is not initialized correctly
Vue.prototype.$i18n = function (key) {
return key;
};
return;
}
// initialize the replacement function
let render = renderFn(identifiers, config.warnings);
Vue.prototype.$getLanguage = function () {
return null;
};
// get localized string from store. note that we pass the arguments passed
// to the function directly to the translateInLanguage function
let translate = function $t() {
Vue.prototype.$setLanguage = function () {
console.error('i18n: i18n vuex module is not correctly initialized');
};
// get the current language from the store
let locale = store.state[moduleName].locale;
return;
}
// initialize the replacement function
var render = renderFn(identifiers, config.warnings);
return translateInLanguage(locale, ...arguments);
};
// get localized string from store. note that we pass the arguments passed
// to the function directly to the translateInLanguage function
var translate = function $t() {
// get localized string from store in a given language if available.
// there are two possible signatures for the function.
// we will check the arguments to make up the options passed.
// 1: locale, key, options, pluralization
// 2: locale, key, defaultValue, options, pluralization
let translateInLanguage = function translateInLanguage(locale) {
// get the current language from the store
var locale = store.state[moduleName].locale;
// read the function arguments
let args = arguments;
return translateInLanguage.apply(undefined, [locale].concat(Array.prototype.slice.call(arguments)));
};
// initialize options
let key = '';
let defaultValue = '';
let options = {};
let pluralization = null;
// get localized string from store in a given language if available.
// there are two possible signatures for the function.
// we will check the arguments to make up the options passed.
// 1: locale, key, options, pluralization
// 2: locale, key, defaultValue, options, pluralization
var translateInLanguage = function translateInLanguage(locale) {
let count = args.length;
// read the function arguments
var args = arguments;
// check if a default value was specified and fill options accordingly
if (count >= 3 && typeof args[2] === 'string') {
// initialize options
var key = '';
var defaultValue = '';
var options = {};
var pluralization = null;
key = args[1];
defaultValue = args[2];
var count = args.length;
if (count > 3) {
options = args[3];
}
// check if a default value was specified and fill options accordingly
if (count >= 3 && typeof args[2] === 'string') {
if (count > 4) {
pluralization = args[4];
}
} else {
key = args[1];
defaultValue = args[2];
key = args[1];
if (count > 3) {
options = args[3];
}
// default value was not specified and is therefore the same as the key
defaultValue = key;
if (count > 4) {
pluralization = args[4];
}
} else {
if (count > 2) {
options = args[2];
}
key = args[1];
if (count > 3) {
pluralization = args[3];
}
}
// default value was not specified and is therefore the same as the key
defaultValue = key;
// return the default value if the locale is not set (could happen on initialization)
if (!locale) {
if (config.warnings) console.warn('i18n: i18n locale is not set when trying to access translations:', key);
return defaultValue;
}
if (count > 2) {
options = args[2];
}
// get the translations from the store
let translations = store.state[moduleName].translations;
if (count > 3) {
pluralization = args[3];
}
}
// get the last resort fallback from the store
let fallback = store.state[moduleName].fallback;
// return the default value if the locale is not set (could happen on initialization)
if (!locale) {
if (config.warnings) console.warn('i18n: i18n locale is not set when trying to access translations:', key);
return defaultValue;
}
// split locale by - to support partial fallback for regional locales
// like de-CH, en-UK
let localeRegional = locale.split('-');
// get the translations from the store
var translations = store.state[moduleName].translations;
// flag for translation to exist or not
let translationExists = true;
// get the last resort fallback from the store
var fallback = store.state[moduleName].fallback;
// check if the language exists in the store. return the key if not
if (translations.hasOwnProperty(locale) === false) {
translationExists = false;
// split locale by - to support partial fallback for regional locales
// like de-CH, en-UK
var localeRegional = locale.split('-');
// check if the key exists in the store. return the key if not
} else if (translations[locale].hasOwnProperty(key) === false) {
translationExists = false;
}
// flag for translation to exist or not
var translationExists = true;
// return the value from the store
if (translationExists === true) {
return render(locale, translations[locale][key], options, pluralization);
}
// check if the language exists in the store. return the key if not
if (translations.hasOwnProperty(locale) === false) {
translationExists = false;
// 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 the key exists in the store. return the key if not
} else if (translations[locale].hasOwnProperty(key) === false) {
translationExists = false;
}
// invoke a method if a translation is not found
let asyncTranslation = onTranslationNotFound(locale, key, defaultValue);
// return the value from the store
if (translationExists === true) {
return render(locale, translations[locale][key], options, pluralization);
}
// resolve async translations by updating the store
if (asyncTranslation) {
Promise.resolve(asyncTranslation).then(value => {
let additionalTranslations = {};
additionalTranslations[key] = value;
addLocale(locale, additionalTranslations);
});
}
// 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) {
return render(locale, defaultValue, options, pluralization);
}
// invoke a method if a translation is not found
var asyncTranslation = onTranslationNotFound(locale, key, defaultValue);
// 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(fallback, defaultValue, options, pluralization);
}
// resolve async translations by updating the store
if (asyncTranslation) {
Promise.resolve(asyncTranslation).then(function (value) {
var additionalTranslations = {};
additionalTranslations[key] = value;
addLocale(locale, additionalTranslations);
});
}
return render(locale, translations[fallback][key], options, pluralization);
};
// check if a vaild fallback exists in the store.
// return the default value if not
if (translations.hasOwnProperty(fallback) === false) {
return render(locale, defaultValue, options, pluralization);
}
// check if the given key exists in the current locale
let checkKeyExists = function checkKeyExists(key, scope = 'fallback') {
// 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(fallback, defaultValue, options, pluralization);
}
// get the current language from the store
let locale = store.state[moduleName].locale;
let fallback = store.state[moduleName].fallback;
let translations = store.state[moduleName].translations;
return render(locale, translations[fallback][key], options, pluralization);
};
// check the current translation
if (translations.hasOwnProperty(locale) && translations[locale].hasOwnProperty(key)) {
return true;
}
// check if the given key exists in the current locale
var checkKeyExists = function checkKeyExists(key) {
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'fallback';
if (scope == 'strict') {
return false;
}
// check any localized translations
let localeRegional = locale.split('-');
// get the current language from the store
var locale = store.state[moduleName].locale;
var fallback = store.state[moduleName].fallback;
var translations = store.state[moduleName].translations;
if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) && translations[localeRegional[0]].hasOwnProperty(key)) {
return true;
}
// check the current translation
if (translations.hasOwnProperty(locale) && translations[locale].hasOwnProperty(key)) {
return true;
}
if (scope == 'locale') {
return false;
}
if (scope == 'strict') {
return false;
}
// check if a fallback locale exists
if (translations.hasOwnProperty(fallback) && translations[fallback].hasOwnProperty(key)) {
return true;
}
// check any localized translations
var localeRegional = locale.split('-');
// key does not exist in the store
return false;
};
if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) && translations[localeRegional[0]].hasOwnProperty(key)) {
return true;
}
// set fallback locale
let setFallbackLocale = function setFallbackLocale(locale) {
store.dispatch({
type: `${moduleName}/setFallbackLocale`,
locale: locale
});
};
if (scope == 'locale') {
return false;
}
// set the current locale
let setLocale = function setLocale(locale) {
store.dispatch({
type: `${moduleName}/setLocale`,
locale: locale
});
};
// check if a fallback locale exists
if (translations.hasOwnProperty(fallback) && translations[fallback].hasOwnProperty(key)) {
return true;
}
// get the current locale
let getLocale = function getLocale() {
return store.state[moduleName].locale;
};
// key does not exist in the store
return false;
};
// get all available locales
let getLocales = function getLocales() {
return Object.keys(store.state[moduleName].translations);
};
// set fallback locale
var setFallbackLocale = function setFallbackLocale(locale) {
store.dispatch({
type: moduleName + '/setFallbackLocale',
locale: locale
});
};
// add predefined translations to the store (keeping existing information)
let addLocale = function addLocale(locale, translations) {
return store.dispatch({
type: `${moduleName}/addLocale`,
locale: locale,
translations: translations
});
};
// set the current locale
var setLocale = function setLocale(locale) {
store.dispatch({
type: moduleName + '/setLocale',
locale: locale
});
};
// replace all locale information in the store
let replaceLocale = function replaceLocale(locale, translations) {
return store.dispatch({
type: `${moduleName}/replaceLocale`,
locale: locale,
translations: translations
});
};
// get the current locale
var getLocale = function getLocale() {
return store.state[moduleName].locale;
};
// remove the givne locale from the store
let removeLocale = function removeLocale(locale) {
if (store.state[moduleName].translations.hasOwnProperty(locale)) {
store.dispatch({
type: `${moduleName}/removeLocale`,
locale: locale
});
}
};
// get all available locales
var getLocales = function getLocales() {
return Object.keys(store.state[moduleName].translations);
};
// we are phasing out the exists function
let phaseOutExistsFn = function phaseOutExistsFn(locale) {
if (config.warnings) console.warn('i18n: $i18n.exists is depreceated. Please use $i18n.localeExists instead. It provides exactly the same functionality.');
return checkLocaleExists(locale);
};
// add predefined translations to the store (keeping existing information)
var addLocale = function addLocale(locale, translations) {
return store.dispatch({
type: moduleName + '/addLocale',
locale: locale,
translations: translations
});
};
// check if the given locale is already loaded
let checkLocaleExists = function checkLocaleExists(locale) {
return store.state[moduleName].translations.hasOwnProperty(locale);
};
// replace all locale information in the store
var replaceLocale = function replaceLocale(locale, translations) {
return store.dispatch({
type: moduleName + '/replaceLocale',
locale: locale,
translations: translations
});
};
// register vue prototype methods
Vue.prototype.$i18n = {
locale: getLocale,
locales: getLocales,
set: setLocale,
add: addLocale,
replace: replaceLocale,
remove: removeLocale,
fallback: setFallbackLocale,
localeExists: checkLocaleExists,
keyExists: checkKeyExists,
// remove the givne locale from the store
var removeLocale = function removeLocale(locale) {
if (store.state[moduleName].translations.hasOwnProperty(locale)) {
store.dispatch({
type: moduleName + '/removeLocale',
locale: locale
});
}
};
translate: translate,
translateIn: translateInLanguage,
// we are phasing out the exists function
var phaseOutExistsFn = function phaseOutExistsFn(locale) {
if (config.warnings) console.warn('i18n: $i18n.exists is depreceated. Please use $i18n.localeExists instead. It provides exactly the same functionality.');
return checkLocaleExists(locale);
};
exists: phaseOutExistsFn
};
// check if the given locale is already loaded
var checkLocaleExists = function checkLocaleExists(locale) {
return store.state[moduleName].translations.hasOwnProperty(locale);
};
// register global methods
Vue.i18n = {
locale: getLocale,
locales: getLocales,
set: setLocale,
add: addLocale,
replace: replaceLocale,
remove: removeLocale,
fallback: setFallbackLocale,
translate: translate,
translateIn: translateInLanguage,
localeExists: checkLocaleExists,
keyExists: checkKeyExists,
// register vue prototype methods
Vue.prototype.$i18n = {
locale: getLocale,
locales: getLocales,
set: setLocale,
add: addLocale,
replace: replaceLocale,
remove: removeLocale,
fallback: setFallbackLocale,
localeExists: checkLocaleExists,
keyExists: checkKeyExists,
exists: phaseOutExistsFn
};
translate: translate,
translateIn: translateInLanguage,
// register the translation function on the vue instance directly
Vue.prototype.$t = translate;
exists: phaseOutExistsFn
};
// register the specific language translation function on the vue instance directly
Vue.prototype.$tlang = translateInLanguage;
// register global methods
Vue.i18n = {
locale: getLocale,
locales: getLocales,
set: setLocale,
add: addLocale,
replace: replaceLocale,
remove: removeLocale,
fallback: setFallbackLocale,
translate: translate,
translateIn: translateInLanguage,
localeExists: checkLocaleExists,
keyExists: checkKeyExists,
// register a filter function for translations
Vue.filter(translateFilterName, translate);
};
exists: phaseOutExistsFn
};
// renderFn will initialize a function to render the variable substitutions in
// the translation string. identifiers specify the tags will be used to find
// variable substitutions, i.e. {test} or {{test}}, note that we are using a
// closure to avoid recompilation of the regular expression to match tags on
// every render cycle.
let renderFn = function (identifiers, warnings = true) {
// register the translation function on the vue instance directly
Vue.prototype.$t = translate;
if (identifiers == null || identifiers.length != 2) {
console.warn('i18n: You must specify the start and end character identifying variable substitutions');
}
// register the specific language translation function on the vue instance directly
Vue.prototype.$tlang = translateInLanguage;
// construct a regular expression ot find variable substitutions, i.e. {test}
let matcher = new RegExp('' + identifiers[0] + '{1}(\\w{1}|\\w.+?)' + identifiers[1] + '{1}', 'g');
// register a filter function for translations
Vue.filter(translateFilterName, translate);
};
// define the replacement function
let replace = function replace(translation, replacements) {
// renderFn will initialize a function to render the variable substitutions in
// the translation string. identifiers specify the tags will be used to find
// variable substitutions, i.e. {test} or {{test}}, note that we are using a
// closure to avoid recompilation of the regular expression to match tags on
// every render cycle.
var renderFn = function renderFn(identifiers) {
var warnings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
// check if the object has a replace property
if (!translation.replace) {
return translation;
}
return translation.replace(matcher, function (placeholder) {
if (identifiers == null || identifiers.length != 2) {
console.warn('i18n: You must specify the start and end character identifying variable substitutions');
}
// remove the identifiers (can be set on the module level)
let key = placeholder.replace(identifiers[0], '').replace(identifiers[1], '');
// construct a regular expression ot find variable substitutions, i.e. {test}
var matcher = new RegExp('' + identifiers[0] + '{1}\\w.+?' + identifiers[1] + '{1}', 'g');
if (replacements[key] !== undefined) {
return replacements[key];
}
// define the replacement function
var replace = function replace(translation, replacements) {
// warn user that the placeholder has not been found
if (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);
if (console.groupEnd) {
console.groupEnd();
}
}
// check if the object has a replace property
if (!translation.replace) {
return translation;
}
// return the original placeholder
return placeholder;
});
};
return translation.replace(matcher, function (placeholder) {
// the render function will replace variable substitutions and prepare the
// translations for rendering
let render = function render(locale, translation, replacements = {}, pluralization = null) {
// get the type of the property
let objType = typeof translation;
let pluralizationType = typeof pluralization;
// remove the identifiers (can be set on the module level)
var key = placeholder.replace(identifiers[0], '').replace(identifiers[1], '');
let resolvePlaceholders = function () {
if (replacements[key] !== undefined) {
return replacements[key];
}
if (isArray$1(translation)) {
// warn user that the placeholder has not been found
if (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);
if (console.groupEnd) {
console.groupEnd();
}
}
// replace the placeholder elements in all sub-items
return translation.map(item => {
return replace(item, replacements, false);
});
} else if (objType === 'string') {
return replace(translation, replacements, true);
}
};
// return the original placeholder
return placeholder;
});
};
// return translation item directly
if (pluralization === null) {
return resolvePlaceholders();
}
// the render function will replace variable substitutions and prepare the
// translations for rendering
var render = function render(locale, translation) {
var replacements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var pluralization = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
// check if pluralization value is countable
if (pluralizationType !== 'number') {
if (warnings) console.warn('i18n: pluralization is not a number');
return resolvePlaceholders();
}
// get the type of the property
var objType = typeof translation === 'undefined' ? 'undefined' : _typeof(translation);
var pluralizationType = typeof pluralization === 'undefined' ? 'undefined' : _typeof(pluralization);
// --- handle pluralizations ---
var resolvePlaceholders = function resolvePlaceholders() {
// replace all placeholders
let resolvedTranslation = resolvePlaceholders();
if (isArray$1(translation)) {
// initialize pluralizations
let pluralizations = null;
// replace the placeholder elements in all sub-items
return translation.map(function (item) {
return replace(item, replacements, false);
});
} else if (objType === 'string') {
return replace(translation, replacements, true);
}
};
// if translations are already an array and have more than one entry,
// we will not perform a split operation on :::
if (isArray$1(resolvedTranslation) && resolvedTranslation.length > 0) {
pluralizations = resolvedTranslation;
} else {
// split translation strings by ::: to find create the pluralization array
pluralizations = resolvedTranslation.split(':::');
}
// return translation item directly
if (pluralization === null) {
return resolvePlaceholders();
}
// determine the pluralization version to use by locale
let index = plurals.getTranslationIndex(locale, pluralization);
// check if pluralization value is countable
if (pluralizationType !== 'number') {
if (warnings) console.warn('i18n: pluralization is not a number');
return resolvePlaceholders();
}
// check if the specified index is present in the pluralization
if (typeof pluralizations[index] === 'undefined') {
if (warnings) {
console.warn('i18n: pluralization not provided in locale', translation, locale, index);
}
// --- handle pluralizations ---
// return the first element of the pluralization by default
return pluralizations[0].trim();
}
// replace all placeholders
var resolvedTranslation = resolvePlaceholders();
// return the requested item from the pluralizations
return pluralizations[index].trim();
};
// initialize pluralizations
var pluralizations = null;
// return the render function to the caller
return render;
};
// if translations are already an array and have more than one entry,
// we will not perform a split operation on :::
if (isArray$1(resolvedTranslation) && resolvedTranslation.length > 0) {
pluralizations = resolvedTranslation;
} else {
// split translation strings by ::: to find create the pluralization array
pluralizations = resolvedTranslation.split(':::');
}
// check if the given object is an array
function isArray$1(obj) {
return !!obj && Array === obj.constructor;
}
// determine the pluralization version to use by locale
var index = plurals.getTranslationIndex(locale, pluralization);
// export both modules as one file
var index = {
store: i18nVuexModule,
plugin: VuexI18nPlugin
};
// check if the specified index is present in the pluralization
if (typeof pluralizations[index] === 'undefined') {
if (warnings) {
console.warn('i18n: pluralization not provided in locale', translation, locale, index);
}
return index;
// return the first element of the pluralization by default
return pluralizations[0].trim();
}
// return the requested item from the pluralizations
return pluralizations[index].trim();
};
// return the render function to the caller
return render;
};
// check if the given object is an array
function isArray$1(obj) {
return !!obj && Array === obj.constructor;
}
// export both modules as one file
var index = {
store: i18nVuexModule,
plugin: VuexI18nPlugin
};
return index;
})));
{
"name": "vuex-i18n",
"version": "1.10.7",
"version": "1.10.8",
"description": "Easy localization for vue-components using vuex as data store",

@@ -11,10 +11,3 @@ "directories": {

"main": "dist/vuex-i18n.es.js",
"files": [
"dist",
"test"
],
"scripts": {
"build": "rollup -c rollup.config.js",
"minify": "uglifyjs dist/vuex-i18n.umd.js --output dist/vuex-i18n.min.js --compress --mangle"
},
"files": ["dist"],
"repository": {

@@ -21,0 +14,0 @@ "type": "git",

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