diff --git a/README.md b/README.md index e62a9da..29065f1 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ module.exports = { 'locale', 'resource' ], + defaultLng: 'en', defaultNs: 'resource', defaultValue: '__STRING_NOT_TRANSLATED__', resource: { @@ -498,6 +499,7 @@ Below are the configuration options with their default values: }, lngs: ['en'], ns: ['translation'], + defaultLng: 'en', defaultNs: 'translation', defaultValue: '', resource: { @@ -620,6 +622,12 @@ Type: `String` or `Array` Default: `['translation']` A namespace string or an array of namespaces. +#### defaultLng + +Type: `String` Default: `'en'` + +The default language used for checking default values. + #### defaultNs Type: `String` Default: `'translation'` diff --git a/package.json b/package.json index 4c9f468..237245b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "i18next-scanner", - "version": "2.4.0", + "version": "2.4.1", "description": "Scan your code, extract translation keys/values, and merge them into i18n resource files.", "homepage": "https://github.com/i18next/i18next-scanner", "author": "Cheton Wu ", diff --git a/src/parser.js b/src/parser.js index 45412c2..ed236e9 100644 --- a/src/parser.js +++ b/src/parser.js @@ -36,6 +36,8 @@ const defaults = { ns: [], // string or array of namespaces + defaultLng: 'en', // default language used for checking default values + defaultNs: 'translation', // default namespace used if not passed to translation function defaultValue: '', // default value used if not passed to `parser.set` @@ -636,6 +638,7 @@ class Parser { plural, pluralFallback, pluralSeparator, + defaultLng, defaultValue } = this.options; const keys = _.isString(keySeparator) @@ -743,10 +746,9 @@ class Parser { if (!resLoad[resKey]) { // Use `options.defaultValue` if specified resLoad[resKey] = options.defaultValue; - } else if (resLoad[resKey] !== options.defaultValue) { - // We already had a different default. - const k = chalk.yellow(JSON.stringify(resKey)); - this.log(`i18next-scanner: Translation key ${k} has multiple different default values. Using first default`); + } else if ((resLoad[resKey] !== options.defaultValue) && (lng === defaultLng)) { + // A default value has provided but it's different with the expected default + this.log(`i18next-scanner: The translation key ${chalk.yellow(JSON.stringify(resKey))} has a different default value, you may need to check the translation key of default language (${defaultLng})`); } } diff --git a/test/parser.js b/test/parser.js index 0b509a8..0563485 100644 --- a/test/parser.js +++ b/test/parser.js @@ -29,7 +29,7 @@ test('set warns about conflicting defaults', (t) => { parser.set('key', { defaultValue: 'Default text' }); parser.set('key', { defaultValue: 'Another text' }); t.same(parser.get('key'), 'Default text'); - t.match(logText, /different default/); + t.match(logText, /different default value/); t.end(); });