i18next-scanner
Advanced tools
Comparing version 1.9.3 to 1.9.4
@@ -265,3 +265,3 @@ 'use strict'; | ||
} catch (err) { | ||
_this.debuglog('Unable to load ' + JSON.stringify(resPath)); | ||
_this.log('Unable to load ' + JSON.stringify(resPath)); | ||
} | ||
@@ -271,3 +271,3 @@ }); | ||
this.debuglog('[i18next-scanner] Parser(options): ' + JSON.stringify(this.options)); | ||
this.log('Parser: options=' + JSON.stringify(this.options)); | ||
} | ||
@@ -279,7 +279,6 @@ | ||
_createClass(Parser, [{ | ||
key: 'debuglog', | ||
value: function debuglog() { | ||
key: 'log', | ||
value: function log() { | ||
var debug = this.options.debug; | ||
if (debug) { | ||
@@ -412,4 +411,4 @@ for (var _len = arguments.length, args = Array(_len), _key2 = 0; _key2 < _len; _key2++) { | ||
} catch (err) { | ||
_this2.debuglog('Unable to parse code "' + code + '"'); | ||
_this2.debuglog(err); | ||
_this2.log('Unable to parse code "' + code + '"'); | ||
_this2.log(err); | ||
} | ||
@@ -635,4 +634,4 @@ } | ||
if (!(0, _isObject2.default)(resLoad)) { | ||
// skip undefined namespace | ||
console.log('The namespace "' + ns + '" does not exist:', { key: key, options: options }); | ||
// Skip undefined namespace | ||
_this4.log('The namespace "' + ns + '" does not exist:', { key: key, options: options }); | ||
return; | ||
@@ -649,3 +648,2 @@ } | ||
resScan = resScan[key]; | ||
return; // continue | ||
@@ -674,7 +672,22 @@ } | ||
// http://i18next.com/translate/context/ | ||
// Note. The parser only supports string type for "context" | ||
var containsContext = context && options.context !== undefined && typeof options.context === 'string' && options.context !== ''; | ||
var containsContext = function () { | ||
if (!context) { | ||
return false; | ||
} | ||
if ((0, _isUndefined2.default)(options.context)) { | ||
return false; | ||
} | ||
return (0, _isFunction2.default)(context) ? context(lng, ns, key, options) : !!context; | ||
}(); | ||
// http://i18next.com/translate/pluralSimple/ | ||
var containsPlural = plural && options.count !== undefined; | ||
var containsPlural = function () { | ||
if (!plural) { | ||
return false; | ||
} | ||
if ((0, _isUndefined2.default)(options.count)) { | ||
return false; | ||
} | ||
return (0, _isFunction2.default)(plural) ? plural(lng, ns, key, options) : !!plural; | ||
}(); | ||
@@ -710,3 +723,3 @@ if (!containsContext && !containsPlural) { | ||
} | ||
_this4.debuglog('Added a new translation key { %s: %s } to %s', JSON.stringify(resKey), JSON.stringify(resLoad[resKey]), JSON.stringify(_this4.formatResourceLoadPath(lng, ns))); | ||
_this4.log('Added a new translation key { %s: %s } to %s', JSON.stringify(resKey), JSON.stringify(resLoad[resKey]), JSON.stringify(_this4.formatResourceLoadPath(lng, ns))); | ||
} | ||
@@ -713,0 +726,0 @@ |
{ | ||
"name": "i18next-scanner", | ||
"version": "1.9.3", | ||
"version": "1.9.4", | ||
"description": "Scan your code, extract translation keys/values, and merge them into i18n resource files.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/i18next/i18next-scanner", |
@@ -489,6 +489,12 @@ # i18next-scanner [![build status](https://travis-ci.org/i18next/i18next-scanner.svg?branch=master)](https://travis-ci.org/i18next/i18next-scanner) [![Coverage Status](https://coveralls.io/repos/i18next/i18next-scanner/badge.svg?branch=master&service=github)](https://coveralls.io/github/i18next/i18next-scanner?branch=master) | ||
Type: `Boolean` Default: `true` | ||
Type: `Boolean` or `Function` Default: `true` | ||
Whether to add context form key. | ||
```js | ||
context: function(lng, ns, key, options) { | ||
return true; | ||
} | ||
``` | ||
#### contextFallback | ||
@@ -508,6 +514,12 @@ | ||
Type: `Boolean` Default: `true` | ||
Type: `Boolean` or `Function` Default: `true` | ||
Whether to add plural form key. | ||
```js | ||
plural: function(lng, ns, key, options) { | ||
return true; | ||
} | ||
``` | ||
#### pluralFallback | ||
@@ -514,0 +526,0 @@ |
@@ -199,3 +199,3 @@ /* eslint no-console: 0 */ | ||
} catch (err) { | ||
this.debuglog('Unable to load ' + JSON.stringify(resPath)); | ||
this.log('Unable to load ' + JSON.stringify(resPath)); | ||
} | ||
@@ -205,7 +205,6 @@ }); | ||
this.debuglog('[i18next-scanner] Parser(options): ' + JSON.stringify(this.options)); | ||
this.log(`Parser: options=${JSON.stringify(this.options)}`); | ||
} | ||
debuglog(...args) { | ||
log(...args) { | ||
const { debug } = this.options; | ||
if (debug) { | ||
@@ -329,4 +328,4 @@ console.log.apply(this, args); | ||
} catch (err) { | ||
this.debuglog(`Unable to parse code "${code}"`); | ||
this.debuglog(err); | ||
this.log(`Unable to parse code "${code}"`); | ||
this.log(err); | ||
} | ||
@@ -538,4 +537,4 @@ } | ||
if (!isObject(resLoad)) { // skip undefined namespace | ||
console.log('The namespace "' + ns + '" does not exist:', { key, options }); | ||
if (!isObject(resLoad)) { // Skip undefined namespace | ||
this.log('The namespace "' + ns + '" does not exist:', { key, options }); | ||
return; | ||
@@ -552,3 +551,2 @@ } | ||
resScan = resScan[key]; | ||
return; // continue | ||
@@ -577,11 +575,26 @@ } | ||
// http://i18next.com/translate/context/ | ||
// Note. The parser only supports string type for "context" | ||
const containsContext = context | ||
&& (options.context !== undefined) | ||
&& (typeof options.context === 'string') | ||
&& (options.context !== ''); | ||
const containsContext = (() => { | ||
if (!context) { | ||
return false; | ||
} | ||
if (isUndefined(options.context)) { | ||
return false; | ||
} | ||
return isFunction(context) | ||
? context(lng, ns, key, options) | ||
: !!context; | ||
})(); | ||
// http://i18next.com/translate/pluralSimple/ | ||
const containsPlural = plural | ||
&& (options.count !== undefined); | ||
const containsPlural = (() => { | ||
if (!plural) { | ||
return false; | ||
} | ||
if (isUndefined(options.count)) { | ||
return false; | ||
} | ||
return isFunction(plural) | ||
? plural(lng, ns, key, options) | ||
: !!plural; | ||
})(); | ||
@@ -619,3 +632,3 @@ if (!containsContext && !containsPlural) { | ||
} | ||
this.debuglog('Added a new translation key { %s: %s } to %s', | ||
this.log('Added a new translation key { %s: %s } to %s', | ||
JSON.stringify(resKey), | ||
@@ -622,0 +635,0 @@ JSON.stringify(resLoad[resKey]), |
@@ -347,17 +347,52 @@ import fs from 'fs'; | ||
test('Plural', (t) => { | ||
const parser = new Parser(); | ||
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/plural.js'), 'utf-8'); | ||
parser.parseFuncFromString(content, { propsFilter: props => props }); | ||
t.same(parser.get(), { | ||
en: { | ||
translation: { | ||
"key": "", | ||
"key_plural": "", | ||
"keyWithCount": "", | ||
"keyWithCount_plural": "", | ||
"keyWithVariable": "", | ||
"keyWithVariable_plural": "" | ||
test('Default options', (t) => { | ||
const parser = new Parser() | ||
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/plural.js'), 'utf-8'); | ||
parser.parseFuncFromString(content, { propsFilter: props => props }); | ||
t.same(parser.get(), { | ||
en: { | ||
translation: { | ||
"key": "", | ||
"key_plural": "", | ||
"keyWithCount": "", | ||
"keyWithCount_plural": "", | ||
"keyWithVariable": "", | ||
"keyWithVariable_plural": "" | ||
} | ||
} | ||
} | ||
}); | ||
t.end(); | ||
}); | ||
test('User defined function', (t) => { | ||
const parser = new Parser({ | ||
plural: (lng, ns, key, options) => { | ||
if (key === 'key') { | ||
return false; | ||
} | ||
if (key === 'keyWithCount') { | ||
return true; | ||
} | ||
if (key === 'keyWithVariable') { | ||
return true; | ||
} | ||
return true; | ||
} | ||
}); | ||
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/plural.js'), 'utf-8'); | ||
parser.parseFuncFromString(content, { propsFilter: props => props }); | ||
t.same(parser.get(), { | ||
en: { | ||
translation: { | ||
"key": "", | ||
"keyWithCount": "", | ||
"keyWithCount_plural": "", | ||
"keyWithVariable": "", | ||
"keyWithVariable_plural": "" | ||
} | ||
} | ||
}); | ||
t.end(); | ||
}); | ||
t.end(); | ||
@@ -384,14 +419,43 @@ }); | ||
test('Context', (t) => { | ||
const parser = new Parser(); | ||
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/context.js'), 'utf-8'); | ||
parser.parseFuncFromString(content, { propsFilter: props => props }); | ||
t.same(parser.get(), { | ||
en: { | ||
translation: { | ||
"friend": "", | ||
"friend_male": "", | ||
"friend_female": "" | ||
test('Default options', (t) => { | ||
const parser = new Parser(); | ||
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/context.js'), 'utf-8'); | ||
parser.parseFuncFromString(content, { propsFilter: props => props }); | ||
t.same(parser.get(), { | ||
en: { | ||
translation: { | ||
"friend": "", | ||
"friend_male": "", | ||
"friend_female": "" | ||
} | ||
} | ||
} | ||
}); | ||
t.end(); | ||
}); | ||
test('User defined function', (t) => { | ||
const parser = new Parser({ | ||
context: (lng, ns, key, options) => { | ||
if (options.context === 'male') { | ||
return true; | ||
} | ||
if (options.context === 'female') { | ||
return false; | ||
} | ||
return true; | ||
} | ||
}); | ||
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/context.js'), 'utf-8'); | ||
parser.parseFuncFromString(content, { propsFilter: props => props }); | ||
t.same(parser.get(), { | ||
en: { | ||
translation: { | ||
"friend": "", | ||
"friend_male": "" | ||
} | ||
} | ||
}); | ||
t.end(); | ||
}); | ||
t.end(); | ||
@@ -398,0 +462,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126715
2601
560