Skip to content

Commit

Permalink
new build
Browse files Browse the repository at this point in the history
  • Loading branch information
tikiatua committed Dec 11, 2018
1 parent 1902edd commit b759cfe
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 43 deletions.
31 changes: 17 additions & 14 deletions dist/vuex-i18n.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ VuexI18nPlugin.install = function install(Vue, store, config) {
}

// merge default options with user supplied options
var mergedConfig = Object.assign({
config = Object.assign({
warnings: true,
moduleName: 'i18n',
identifiers: ['{', '}'],
preserveState: false,
Expand All @@ -367,21 +368,21 @@ VuexI18nPlugin.install = function install(Vue, store, config) {
}, config);

// define module name and identifiers as constants to prevent any changes
var moduleName = mergedConfig.moduleName;
var identifiers = mergedConfig.identifiers;
var translateFilterName = mergedConfig.translateFilterName;
var moduleName = config.moduleName;
var identifiers = config.identifiers;
var translateFilterName = config.translateFilterName;

// initialize the onTranslationNotFound function and make sure it is actually
// a function
var onTranslationNotFound = mergedConfig.onTranslationNotFound;
var onTranslationNotFound = config.onTranslationNotFound;
if (typeof onTranslationNotFound !== 'function') {
console.error('i18n: i18n config option onTranslationNotFound must be a function');
onTranslationNotFound = function onTranslationNotFound() {};
}

// 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: mergedConfig.preserveState });
store.registerModule(moduleName, i18nVuexModule, { preserveState: config.preserveState });

// check if the plugin was correctly initialized
if (store.state.hasOwnProperty(moduleName) === false) {
Expand All @@ -403,7 +404,7 @@ VuexI18nPlugin.install = function install(Vue, store, config) {
return;
}
// initialize the replacement function
var render = renderFn(identifiers);
var 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
Expand Down Expand Up @@ -623,7 +624,7 @@ VuexI18nPlugin.install = function install(Vue, store, config) {

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

Expand Down Expand Up @@ -683,18 +684,18 @@ VuexI18nPlugin.install = function install(Vue, store, config) {
// 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;


if (identifiers == null || identifiers.length != 2) {
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] + '\\w+' + identifiers[1], 'g');
var matcher = new RegExp('' + identifiers[0] + '{1}\\w.+?' + identifiers[1] + '{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) {
Expand All @@ -711,7 +712,7 @@ var renderFn = function renderFn(identifiers) {
}

// warn user that the placeholder has not been found
if (warn === true) {
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);
Expand Down Expand Up @@ -755,7 +756,7 @@ var renderFn = function renderFn(identifiers) {

// check if pluralization value is countable
if (pluralizationType !== 'number') {
console.warn('i18n: pluralization is not a number');
if (warnings) console.warn('i18n: pluralization is not a number');
return resolvePlaceholders();
}

Expand All @@ -781,7 +782,9 @@ var renderFn = function renderFn(identifiers) {

// check if the specified index is present in the pluralization
if (typeof pluralizations[index] === 'undefined') {
console.warn('i18n: pluralization not provided in locale', translation, locale, index);
if (warnings) {
console.warn('i18n: pluralization not provided in locale', translation, locale, index);
}

// return the first element of the pluralization by default
return pluralizations[0].trim();
Expand Down
31 changes: 17 additions & 14 deletions dist/vuex-i18n.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ VuexI18nPlugin.install = function install(Vue, store, config) {
}

// merge default options with user supplied options
var mergedConfig = Object.assign({
config = Object.assign({
warnings: true,
moduleName: 'i18n',
identifiers: ['{', '}'],
preserveState: false,
Expand All @@ -365,21 +366,21 @@ VuexI18nPlugin.install = function install(Vue, store, config) {
}, config);

// define module name and identifiers as constants to prevent any changes
var moduleName = mergedConfig.moduleName;
var identifiers = mergedConfig.identifiers;
var translateFilterName = mergedConfig.translateFilterName;
var moduleName = config.moduleName;
var identifiers = config.identifiers;
var translateFilterName = config.translateFilterName;

// initialize the onTranslationNotFound function and make sure it is actually
// a function
var onTranslationNotFound = mergedConfig.onTranslationNotFound;
var onTranslationNotFound = config.onTranslationNotFound;
if (typeof onTranslationNotFound !== 'function') {
console.error('i18n: i18n config option onTranslationNotFound must be a function');
onTranslationNotFound = function onTranslationNotFound() {};
}

// 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: mergedConfig.preserveState });
store.registerModule(moduleName, i18nVuexModule, { preserveState: config.preserveState });

// check if the plugin was correctly initialized
if (store.state.hasOwnProperty(moduleName) === false) {
Expand All @@ -401,7 +402,7 @@ VuexI18nPlugin.install = function install(Vue, store, config) {
return;
}
// initialize the replacement function
var render = renderFn(identifiers);
var 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
Expand Down Expand Up @@ -621,7 +622,7 @@ VuexI18nPlugin.install = function install(Vue, store, config) {

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

Expand Down Expand Up @@ -681,18 +682,18 @@ VuexI18nPlugin.install = function install(Vue, store, config) {
// 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;


if (identifiers == null || identifiers.length != 2) {
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] + '\\w+' + identifiers[1], 'g');
var matcher = new RegExp('' + identifiers[0] + '{1}\\w.+?' + identifiers[1] + '{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) {
Expand All @@ -709,7 +710,7 @@ var renderFn = function renderFn(identifiers) {
}

// warn user that the placeholder has not been found
if (warn === true) {
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);
Expand Down Expand Up @@ -753,7 +754,7 @@ var renderFn = function renderFn(identifiers) {

// check if pluralization value is countable
if (pluralizationType !== 'number') {
console.warn('i18n: pluralization is not a number');
if (warnings) console.warn('i18n: pluralization is not a number');
return resolvePlaceholders();
}

Expand All @@ -779,7 +780,9 @@ var renderFn = function renderFn(identifiers) {

// check if the specified index is present in the pluralization
if (typeof pluralizations[index] === 'undefined') {
console.warn('i18n: pluralization not provided in locale', translation, locale, index);
if (warnings) {
console.warn('i18n: pluralization not provided in locale', translation, locale, index);
}

// return the first element of the pluralization by default
return pluralizations[0].trim();
Expand Down
Loading

0 comments on commit b759cfe

Please sign in to comment.