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.7.0 to 1.8.0

dist/vuex-i18n.umd.js

334

dist/vuex-i18n.cjs.js

@@ -199,140 +199,140 @@ 'use strict';

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;
}
}
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;
}
}
};

@@ -349,7 +349,33 @@

// internationalization plugin for vue js using vuex
VuexI18nPlugin.install = function install(Vue, store) {
var moduleName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'i18n';
var identifiers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['{', '}'];
VuexI18nPlugin.install = function install(Vue, store, config) {
// TODO: remove this block for next major update (API break)
if (typeof arguments[2] === 'string' || typeof arguments[3] === 'string') {
console.warn('VuexI18nPlugin: Registering the plugin with a string for `moduleName` or `identifiers` is deprecated. Use a configuration object instead.', 'https://github.com/dkfbasel/vuex-i18n#setup');
config = {
moduleName: arguments[2],
identifiers: arguments[3]
};
}
// merge default options with user supplied options
var mergedConfig = Object.assign({
moduleName: 'i18n',
identifiers: ['{', '}'],
onTranslationNotFound: function onTranslationNotFound() {}
}, config);
// define module name and identifiers as constants to prevent any changes
var moduleName = mergedConfig.moduleName;
var identifiers = mergedConfig.identifiers;
// initialize the onTranslationNotFound function and make sure it is actually
// a function
var onTranslationNotFound = mergedConfig.onTranslationNotFound;
if (typeof onTranslationNotFound !== 'function') {
console.error('i18n config option onTranslationNotFound must be a function');
onTranslationNotFound = function onTranslationNotFound() {};
}
// register the i18n module in the vuex store
store.registerModule(moduleName, i18nVuexModule);

@@ -437,2 +463,8 @@

// return the default value if the locale is not set (could happen on initialization)
if (!locale) {
console.warn('i18n locale is not set when trying to access translations:', key);
return defaultValue;
}
// get the translations from the store

@@ -449,17 +481,23 @@ var translations = store.state[moduleName].translations;

// flag for translation to exist or not
var translationExist = true;
var translationExists = true;
// check if the language exists in the store. return the key if not
if (translations.hasOwnProperty(locale) === false) {
translationExist = false;
translationExists = false;
// check if the key exists in the store. return the key if not
} else if (translations[locale].hasOwnProperty(key) === false) {
translationExist = false;
translationExists = false;
}
// return the value from the store
if (translationExist === true) {
if (translationExists === true) {
return render(locale, translations[locale][key], options, pluralization);
}
// call custom on function if the translation does not exists
// in the store, but continue with fallback locale and default value rendering
if (translationExists === false) {
onTranslationNotFound(locale, key);
}
// check if a regional locale translation would be available for the key

@@ -645,6 +683,8 @@ // i.e. de for de-CH

if (warn === true) {
console.group('Not all placeholders found');
console.group ? console.group('Not all placeholders found') : console.warn('Not all placeholders found');
console.warn('Text:', translation);
console.warn('Placeholder:', placeholder);
console.groupEnd();
if (console.groupEnd) {
console.groupEnd();
}
}

@@ -651,0 +691,0 @@

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

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;
}
}
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;
}
}
};

@@ -347,7 +347,33 @@

// internationalization plugin for vue js using vuex
VuexI18nPlugin.install = function install(Vue, store) {
var moduleName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'i18n';
var identifiers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['{', '}'];
VuexI18nPlugin.install = function install(Vue, store, config) {
// TODO: remove this block for next major update (API break)
if (typeof arguments[2] === 'string' || typeof arguments[3] === 'string') {
console.warn('VuexI18nPlugin: Registering the plugin with a string for `moduleName` or `identifiers` is deprecated. Use a configuration object instead.', 'https://github.com/dkfbasel/vuex-i18n#setup');
config = {
moduleName: arguments[2],
identifiers: arguments[3]
};
}
// merge default options with user supplied options
var mergedConfig = Object.assign({
moduleName: 'i18n',
identifiers: ['{', '}'],
onTranslationNotFound: function onTranslationNotFound() {}
}, config);
// define module name and identifiers as constants to prevent any changes
var moduleName = mergedConfig.moduleName;
var identifiers = mergedConfig.identifiers;
// initialize the onTranslationNotFound function and make sure it is actually
// a function
var onTranslationNotFound = mergedConfig.onTranslationNotFound;
if (typeof onTranslationNotFound !== 'function') {
console.error('i18n config option onTranslationNotFound must be a function');
onTranslationNotFound = function onTranslationNotFound() {};
}
// register the i18n module in the vuex store
store.registerModule(moduleName, i18nVuexModule);

@@ -435,2 +461,8 @@

// return the default value if the locale is not set (could happen on initialization)
if (!locale) {
console.warn('i18n locale is not set when trying to access translations:', key);
return defaultValue;
}
// get the translations from the store

@@ -447,17 +479,23 @@ var translations = store.state[moduleName].translations;

// flag for translation to exist or not
var translationExist = true;
var translationExists = true;
// check if the language exists in the store. return the key if not
if (translations.hasOwnProperty(locale) === false) {
translationExist = false;
translationExists = false;
// check if the key exists in the store. return the key if not
} else if (translations[locale].hasOwnProperty(key) === false) {
translationExist = false;
translationExists = false;
}
// return the value from the store
if (translationExist === true) {
if (translationExists === true) {
return render(locale, translations[locale][key], options, pluralization);
}
// call custom on function if the translation does not exists
// in the store, but continue with fallback locale and default value rendering
if (translationExists === false) {
onTranslationNotFound(locale, key);
}
// check if a regional locale translation would be available for the key

@@ -643,6 +681,8 @@ // i.e. de for de-CH

if (warn === true) {
console.group('Not all placeholders found');
console.group ? console.group('Not all placeholders found') : console.warn('Not all placeholders found');
console.warn('Text:', translation);
console.warn('Placeholder:', placeholder);
console.groupEnd();
if (console.groupEnd) {
console.groupEnd();
}
}

@@ -649,0 +689,0 @@

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

(function (global, 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.
*/
// define a simple vuex module to handle locale translations
var i18nVuexModule = {
state: {
locale: null,
fallback: null,
translations: {}
},
mutations: {
// set the current locale
SET_LOCALE: function SET_LOCALE(state, payload) {
state.locale = payload.locale;
},
// add a new locale
ADD_LOCALE: function ADD_LOCALE(state, payload) {
// reduce the given translations to a single-depth tree
var translations = flattenTranslations(payload.translations);
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;
}
// 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) {}
},
// replace existing locale information with new translations
REPLACE_LOCALE: function REPLACE_LOCALE(state, payload) {
// reduce the given translations to a single-depth tree
var translations = flattenTranslations(payload.translations);
// replace the translations entirely
state.translations[payload.locale] = 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) {}
},
// remove a locale from the store
REMOVE_LOCALE: function REMOVE_LOCALE(state, payload) {
// check if the given locale is present in the state
if (state.translations.hasOwnProperty(payload.locale)) {
// 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
var translationCopy = Object.assign({}, state.translations);
// remove the given locale
delete translationCopy[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: {
// set the current locale
setLocale: function setLocale(context, payload) {
context.commit({
type: 'SET_LOCALE',
locale: payload.locale
});
},
// add or extend a locale with translations
addLocale: function addLocale(context, payload) {
context.commit({
type: 'ADD_LOCALE',
locale: payload.locale,
translations: payload.translations
});
},
// replace locale information
replaceLocale: function replaceLocale(context, payload) {
context.commit({
type: 'REPLACE_LOCALE',
locale: payload.locale,
translations: payload.translations
});
},
// 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
});
}
}
};
// flattenTranslations will convert object trees for translations into a
// single-depth object tree
var flattenTranslations = function flattenTranslations(translations) {
var toReturn = {};
for (var i in translations) {
// check if the property is present
if (!translations.hasOwnProperty(i)) {
continue;
}
// get the type of the property
var objType = _typeof(translations[i]);
// allow unflattened array of strings
if (isArray(translations[i])) {
var count = translations[i].length;
for (var index = 0; index < count; index++) {
var itemType = _typeof(translations[i][index]);
if (itemType !== 'string') {
console.warn('vuex-i18n:', 'currently only arrays of strings are fully supported', translations[i]);
break;
}
}
toReturn[i] = translations[i];
} else if (objType == 'object' && objType !== null) {
var flatObject = flattenTranslations(translations[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = translations[i];
}
}
return toReturn;
};
// check if the given object is an array
function isArray(obj) {
return !!obj && Array === obj.constructor;
}
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;
}
}
};
/* 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.
*/
// initialize the plugin object
var VuexI18nPlugin = {};
// internationalization plugin for vue js using vuex
VuexI18nPlugin.install = function install(Vue, store) {
var moduleName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'i18n';
var identifiers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['{', '}'];
store.registerModule(moduleName, i18nVuexModule);
// check if the plugin was correctly initialized
if (store.state.hasOwnProperty(moduleName) === false) {
console.error('i18n vuex module is not correctly initialized. Please check the module name:', moduleName);
// always return the key if module is not initialized correctly
Vue.prototype.$i18n = function (key) {
return key;
};
Vue.prototype.$getLanguage = function () {
return null;
};
Vue.prototype.$setLanguage = function () {
console.error('i18n vuex module is not correctly initialized');
};
return;
}
// initialize the replacement function
var render = renderFn(identifiers);
// 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 the current language from the store
var locale = store.state[moduleName].locale;
return translateInLanguage.apply(undefined, [locale].concat(Array.prototype.slice.call(arguments)));
};
// 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) {
// read the function arguments
var args = arguments;
// initialize options
var key = '';
var defaultValue = '';
var options = {};
var pluralization = null;
var count = args.length;
// check if a default value was specified and fill options accordingly
if (count >= 3 && typeof args[2] === 'string') {
key = args[1];
defaultValue = args[2];
if (count > 3) {
options = args[3];
}
if (count > 4) {
pluralization = args[4];
}
} else {
key = args[1];
// default value was not specified and is therefore the same as the key
defaultValue = key;
if (count > 2) {
options = args[2];
}
if (count > 3) {
pluralization = args[3];
}
}
// get the translations from the store
var translations = store.state[moduleName].translations;
// get the last resort fallback from the store
var fallback = store.state[moduleName].fallback;
// split locale by - to support partial fallback for regional locales
// like de-CH, en-UK
var localeRegional = locale.split('-');
// flag for translation to exist or not
var translationExist = true;
// check if the language exists in the store. return the key if not
if (translations.hasOwnProperty(locale) === false) {
translationExist = false;
// check if the key exists in the store. return the key if not
} else if (translations[locale].hasOwnProperty(key) === false) {
translationExist = false;
}
// return the value from the store
if (translationExist === true) {
return render(locale, translations[locale][key], options, pluralization);
}
// check if a regional locale translation would be available for the key
// i.e. de for de-CH
if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) === true && translations[localeRegional[0]].hasOwnProperty(key) === true) {
return render(localeRegional[0], translations[localeRegional[0]][key], options, pluralization);
}
// check if a vaild fallback exists in the store.
// return the default value if not
if (translations.hasOwnProperty(fallback) === false) {
return render(locale, defaultValue, options, pluralization);
}
// 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);
}
return render(locale, translations[fallback][key], options, pluralization);
};
// check if the given key exists in the current locale
var checkKeyExists = function checkKeyExists(key) {
// 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;
// check if the language exists in the store.
if (translations.hasOwnProperty(locale) === false) {
// check if a fallback locale exists
if (translations.hasOwnProperty(fallback) === false) {
return false;
}
// check the fallback locale for the key
return translations[fallback].hasOwnProperty(key);
}
// check if the key exists in the store
return translations[locale].hasOwnProperty(key);
};
// set fallback locale
var setFallbackLocale = function setFallbackLocale(locale) {
store.dispatch({
type: 'setFallbackLocale',
locale: locale
});
};
// set the current locale
var setLocale = function setLocale(locale) {
store.dispatch({
type: 'setLocale',
locale: locale
});
};
// get the current locale
var getLocale = function getLocale() {
return store.state[moduleName].locale;
};
// add predefined translations to the store (keeping existing information)
var addLocale = function addLocale(locale, translations) {
return store.dispatch({
type: 'addLocale',
locale: locale,
translations: translations
});
};
// replace all locale information in the store
var replaceLocale = function replaceLocale(locale, translations) {
return store.dispatch({
type: 'replaceLocale',
locale: locale,
translations: translations
});
};
// remove the givne locale from the store
var removeLocale = function removeLocale(locale) {
if (store.state[moduleName].translations.hasOwnProperty(locale)) {
store.dispatch({
type: 'removeLocale',
locale: locale
});
}
};
// we are phasing out the exists function
var phaseOutExistsFn = function phaseOutExistsFn(locale) {
console.warn('$i18n.exists is depreceated. Please use $i18n.localeExists instead. It provides exatly the same functionality.');
return checkLocaleExists(locale);
};
// check if the given locale is already loaded
var checkLocaleExists = function checkLocaleExists(locale) {
return store.state[moduleName].translations.hasOwnProperty(locale);
};
// register vue prototype methods
Vue.prototype.$i18n = {
locale: getLocale,
set: setLocale,
add: addLocale,
replace: replaceLocale,
remove: removeLocale,
fallback: setFallbackLocale,
localeExists: checkLocaleExists,
keyExists: checkKeyExists,
exists: phaseOutExistsFn
};
// register global methods
Vue.i18n = {
locale: getLocale,
set: setLocale,
add: addLocale,
replace: replaceLocale,
remove: removeLocale,
fallback: setFallbackLocale,
translate: translate,
translateIn: translateInLanguage,
localeExists: checkLocaleExists,
keyExists: checkKeyExists,
exists: phaseOutExistsFn
};
// register the translation function on the vue instance
Vue.prototype.$t = translate;
// register the specific language translation function on the vue instance
Vue.prototype.$tlang = translateInLanguage;
// register a filter function for translations
Vue.filter('translate', translate);
};
// 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) {
if (identifiers == null || identifiers.length != 2) {
console.warn('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] + '\\w+' + identifiers[1], 'g');
// define the replacement function
var replace = function replace(translation, replacements) {
var warn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
// check if the object has a replace property
if (!translation.replace) {
return translation;
}
return translation.replace(matcher, function (placeholder) {
// remove the identifiers (can be set on the module level)
var key = placeholder.replace(identifiers[0], '').replace(identifiers[1], '');
if (replacements[key] !== undefined) {
return replacements[key];
}
// warn user that the placeholder has not been found
if (warn === true) {
console.group('Not all placeholders found');
console.warn('Text:', translation);
console.warn('Placeholder:', placeholder);
console.groupEnd();
}
// return the original placeholder
return placeholder;
});
};
// 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;
// get the type of the property
var objType = typeof translation === 'undefined' ? 'undefined' : _typeof(translation);
var pluralizationType = typeof pluralization === 'undefined' ? 'undefined' : _typeof(pluralization);
var replacedText = function replacedText() {
if (isArray$1(translation)) {
// 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);
}
};
// return translation item directly
if (pluralization === null) {
return replacedText();
}
// check if pluralization value is countable
if (pluralizationType !== 'number') {
console.warn('pluralization is not a number');
return replacedText();
}
// check for pluralization and return the correct part of the string
var translatedText = replacedText().split(':::');
var index = plurals.getTranslationIndex(locale, pluralization);
if (typeof translatedText[index] === 'undefined') {
console.warn('no pluralized translation provided in ', translation);
return translatedText[0].trim();
} else {
return translatedText[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;
}
// import the vuex module for localization
// import the corresponding plugin for vue
// export both modules as one file
var index = {
store: i18nVuexModule,
plugin: VuexI18nPlugin
};
return index;
})));
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.vuexI18n=factory()}(this,function(){"use strict";function isArray(obj){return!!obj&&Array===obj.constructor}function isArray$1(obj){return!!obj&&Array===obj.constructor}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},i18nVuexModule={state:{locale:null,fallback:null,translations:{}},mutations:{SET_LOCALE:function(state,payload){state.locale=payload.locale},ADD_LOCALE:function(state,payload){var translations=flattenTranslations(payload.translations);if(state.translations.hasOwnProperty(payload.locale)){var existingTranslations=state.translations[payload.locale];state.translations[payload.locale]=Object.assign({},existingTranslations,translations)}else state.translations[payload.locale]=translations;try{state.translations.__ob__&&state.translations.__ob__.dep.notify()}catch(ex){}},REPLACE_LOCALE:function(state,payload){var translations=flattenTranslations(payload.translations);state.translations[payload.locale]=translations;try{state.translations.__ob__&&state.translations.__ob__.dep.notify()}catch(ex){}},REMOVE_LOCALE:function(state,payload){if(state.translations.hasOwnProperty(payload.locale)){state.locale===payload.locale&&(state.locale=null);var translationCopy=Object.assign({},state.translations);delete translationCopy[payload.locale],state.translations=translationCopy}},SET_FALLBACK_LOCALE:function(state,payload){state.fallback=payload.locale}},actions:{setLocale:function(context,payload){context.commit({type:"SET_LOCALE",locale:payload.locale})},addLocale:function(context,payload){context.commit({type:"ADD_LOCALE",locale:payload.locale,translations:payload.translations})},replaceLocale:function(context,payload){context.commit({type:"REPLACE_LOCALE",locale:payload.locale,translations:payload.translations})},removeLocale:function(context,payload){context.commit({type:"REMOVE_LOCALE",locale:payload.locale,translations:payload.translations})},setFallbackLocale:function(context,payload){context.commit({type:"SET_FALLBACK_LOCALE",locale:payload.locale})}}},flattenTranslations=function flattenTranslations(translations){var toReturn={};for(var i in translations)if(translations.hasOwnProperty(i)){var objType=_typeof(translations[i]);if(isArray(translations[i])){for(var count=translations[i].length,index=0;index<count;index++)if("string"!==_typeof(translations[i][index])){console.warn("vuex-i18n:","currently only arrays of strings are fully supported",translations[i]);break}toReturn[i]=translations[i]}else if("object"==objType&&null!==objType){var flatObject=flattenTranslations(translations[i]);for(var x in flatObject)flatObject.hasOwnProperty(x)&&(toReturn[i+"."+x]=flatObject[x])}else toReturn[i]=translations[i]}return toReturn},plurals={getTranslationIndex:function(languageCode,n){switch(languageCode){case"ay":case"bo":case"cgg":case"dz":case"fa":case"id":case"ja":case"jbo":case"ka":case"kk":case"km":case"ko":case"ky":case"lo":case"ms":case"my":case"sah":case"su":case"th":case"tt":case"ug":case"vi":case"wo":case"zh":return 0;case"is":return n%10!=1||n%100==11?1:0;case"jv":return 0!==n?1:0;case"mk":return 1===n||n%10==1?0:1;case"ach":case"ak":case"am":case"arn":case"br":case"fil":case"fr":case"gun":case"ln":case"mfe":case"mg":case"mi":case"oc":case"pt_BR":case"tg":case"ti":case"tr":case"uz":case"wa":case"zh":return n>1?1:0;case"lv":return n%10==1&&n%100!=11?0:0!==n?1:2;case"lt":return n%10==1&&n%100!=11?0:n%10>=2&&(n%100<10||n%100>=20)?1:2;case"be":case"bs":case"hr":case"ru":case"sr":case"uk":return n%10==1&&n%100!=11?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2;case"mnk":return 0===n?0:1===n?1:2;case"ro":return 1===n?0:0===n||n%100>0&&n%100<20?1:2;case"pl":return 1===n?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2;case"cs":case"sk":return 1===n?0:n>=2&&n<=4?1:2;case"csb":return 1===n?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2;case"sl":return n%100==1?0:n%100==2?1:n%100==3||n%100==4?2:3;case"mt":return 1===n?0:0===n||n%100>1&&n%100<11?1:n%100>10&&n%100<20?2:3;case"gd":return 1===n||11===n?0:2===n||12===n?1:n>2&&n<20?2:3;case"cy":return 1===n?0:2===n?1:8!==n&&11!==n?2:3;case"kw":return 1===n?0:2===n?1:3===n?2:3;case"ga":return 1===n?0:2===n?1:n>2&&n<7?2:n>6&&n<11?3:4;case"ar":return 0===n?0:1===n?1:2===n?2:n%100>=3&&n%100<=10?3:n%100>=11?4:5;default:return 1!==n?1:0}}},VuexI18nPlugin={};VuexI18nPlugin.install=function(Vue,store,config){"string"!=typeof arguments[2]&&"string"!=typeof arguments[3]||(console.warn("VuexI18nPlugin: Registering the plugin with a string for `moduleName` or `identifiers` is deprecated. Use a configuration object instead.","https://github.com/dkfbasel/vuex-i18n#setup"),config={moduleName:arguments[2],identifiers:arguments[3]});var mergedConfig=Object.assign({moduleName:"i18n",identifiers:["{","}"],onTranslationNotFound:function(){}},config),moduleName=mergedConfig.moduleName,identifiers=mergedConfig.identifiers,onTranslationNotFound=mergedConfig.onTranslationNotFound;if("function"!=typeof onTranslationNotFound&&(console.error("i18n config option onTranslationNotFound must be a function"),onTranslationNotFound=function(){}),store.registerModule(moduleName,i18nVuexModule),!1===store.state.hasOwnProperty(moduleName))return console.error("i18n vuex module is not correctly initialized. Please check the module name:",moduleName),Vue.prototype.$i18n=function(key){return key},Vue.prototype.$getLanguage=function(){return null},void(Vue.prototype.$setLanguage=function(){console.error("i18n vuex module is not correctly initialized")});var render=renderFn(identifiers),translate=function(){var locale=store.state[moduleName].locale;return translateInLanguage.apply(void 0,[locale].concat(Array.prototype.slice.call(arguments)))},translateInLanguage=function(locale){var args=arguments,key="",defaultValue="",options={},pluralization=null,count=args.length;if(count>=3&&"string"==typeof args[2]?(key=args[1],defaultValue=args[2],count>3&&(options=args[3]),count>4&&(pluralization=args[4])):(defaultValue=key=args[1],count>2&&(options=args[2]),count>3&&(pluralization=args[3])),!locale)return console.warn("i18n locale is not set when trying to access translations:",key),defaultValue;var translations=store.state[moduleName].translations,fallback=store.state[moduleName].fallback,localeRegional=locale.split("-"),translationExists=!0;return!1===translations.hasOwnProperty(locale)?translationExists=!1:!1===translations[locale].hasOwnProperty(key)&&(translationExists=!1),!0===translationExists?render(locale,translations[locale][key],options,pluralization):(!1===translationExists&&onTranslationNotFound(locale,key),localeRegional.length>1&&!0===translations.hasOwnProperty(localeRegional[0])&&!0===translations[localeRegional[0]].hasOwnProperty(key)?render(localeRegional[0],translations[localeRegional[0]][key],options,pluralization):!1===translations.hasOwnProperty(fallback)?render(locale,defaultValue,options,pluralization):!1===translations[fallback].hasOwnProperty(key)?render(fallback,defaultValue,options,pluralization):render(locale,translations[fallback][key],options,pluralization))},checkKeyExists=function(key){var locale=store.state[moduleName].locale,fallback=store.state[moduleName].fallback,translations=store.state[moduleName].translations;return!1===translations.hasOwnProperty(locale)?!1!==translations.hasOwnProperty(fallback)&&translations[fallback].hasOwnProperty(key):translations[locale].hasOwnProperty(key)},setFallbackLocale=function(locale){store.dispatch({type:"setFallbackLocale",locale:locale})},setLocale=function(locale){store.dispatch({type:"setLocale",locale:locale})},getLocale=function(){return store.state[moduleName].locale},addLocale=function(locale,translations){return store.dispatch({type:"addLocale",locale:locale,translations:translations})},replaceLocale=function(locale,translations){return store.dispatch({type:"replaceLocale",locale:locale,translations:translations})},removeLocale=function(locale){store.state[moduleName].translations.hasOwnProperty(locale)&&store.dispatch({type:"removeLocale",locale:locale})},phaseOutExistsFn=function(locale){return console.warn("$i18n.exists is depreceated. Please use $i18n.localeExists instead. It provides exatly the same functionality."),checkLocaleExists(locale)},checkLocaleExists=function(locale){return store.state[moduleName].translations.hasOwnProperty(locale)};Vue.prototype.$i18n={locale:getLocale,set:setLocale,add:addLocale,replace:replaceLocale,remove:removeLocale,fallback:setFallbackLocale,localeExists:checkLocaleExists,keyExists:checkKeyExists,exists:phaseOutExistsFn},Vue.i18n={locale:getLocale,set:setLocale,add:addLocale,replace:replaceLocale,remove:removeLocale,fallback:setFallbackLocale,translate:translate,translateIn:translateInLanguage,localeExists:checkLocaleExists,keyExists:checkKeyExists,exists:phaseOutExistsFn},Vue.prototype.$t=translate,Vue.prototype.$tlang=translateInLanguage,Vue.filter("translate",translate)};var renderFn=function(identifiers){null!=identifiers&&2==identifiers.length||console.warn("You must specify the start and end character identifying variable substitutions");var matcher=new RegExp(identifiers[0]+"\\w+"+identifiers[1],"g"),replace=function(translation,replacements){var warn=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return translation.replace?translation.replace(matcher,function(placeholder){var key=placeholder.replace(identifiers[0],"").replace(identifiers[1],"");return void 0!==replacements[key]?replacements[key]:(!0===warn&&(console.group?console.group("Not all placeholders found"):console.warn("Not all placeholders found"),console.warn("Text:",translation),console.warn("Placeholder:",placeholder),console.groupEnd&&console.groupEnd()),placeholder)}):translation};return function(locale,translation){var replacements=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},pluralization=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,objType=void 0===translation?"undefined":_typeof(translation),pluralizationType=void 0===pluralization?"undefined":_typeof(pluralization),replacedText=function(){return isArray$1(translation)?translation.map(function(item){return replace(item,replacements,!1)}):"string"===objType?replace(translation,replacements,!0):void 0};if(null===pluralization)return replacedText();if("number"!==pluralizationType)return console.warn("pluralization is not a number"),replacedText();var translatedText=replacedText().split(":::"),index=plurals.getTranslationIndex(locale,pluralization);return void 0===translatedText[index]?(console.warn("no pluralized translation provided in ",translation),translatedText[0].trim()):translatedText[index].trim()}};return{store:i18nVuexModule,plugin:VuexI18nPlugin}});
{
"name": "vuex-i18n",
"version": "1.7.0",
"version": "1.8.0",
"description": "Easy localization for vue-components using vuex as data store",

@@ -8,3 +8,3 @@ "directories": {

},
"main": "dist/vuex-i18n.min.js",
"main": "dist/vuex-i18n.es.js",
"files": [

@@ -15,3 +15,4 @@ "dist",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "rollup -c rollup.config.js",
"minify": "uglifyjs dist/vuex-i18n.umd.js --output dist/vuex-i18n.min.js --compress"
},

@@ -52,9 +53,9 @@ "repository": {

"devDependencies": {
"babel-core": "^6.26.0",
"babel-plugin-external-helpers": "^6.18.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-es2015-rollup": "^1.2.0",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-commonjs": "^5.0.5",
"rollup-plugin-uglify": "^1.0.1"
"babel-preset-env": "^1.6.1",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-commonjs": "^8.2.6",
"uglify-es": "^3.1.6"
}
}

@@ -93,2 +93,17 @@ # vuex-i18n

You can specify a custom module name for vuex (default is 'i18n') or a callback that is triggered
when a key has no translation for the current locale. Please note, that the function
supplied for onTranslationNotFound will be called if the key is not in the actual
locale, however, the key might still be available in the fallback locale or a
localized locale version. This might need some further work in the future.
```javascript
Vue.use(vuexI18n.plugin, store, {
moduleName: 'i18n',
onTranslationNotFound (locale, key) {
console.warn(`i18n :: Key '${key}' not found for locale '${locale}'`);
}}
);
```
## Usage

@@ -146,4 +161,5 @@ vuex-i18n provides easy access to localized information through the use of

// i.e. to use {{count}} as variable substitution.
// the third parameter defines the module name and is i18n per default
Vue.use(vuexI18n.plugin, store, 'i18n', ['{{','}}']);
Vue.use(vuexI18n.plugin, store, {
identifiers: ['{{','}}']
});
```

@@ -150,0 +166,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc