i18next-scanner
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -53,7 +53,21 @@ var fs = require('fs'); | ||
_.defaults(this.options, defaults); | ||
options = this.options; | ||
var resStore = this.resStore = {}; | ||
var fn = this.fn = { | ||
getResourcePath: function(lng, ns) { | ||
var options = that.options; | ||
var regex = { | ||
'lng': new RegExp(_.escapeRegExp(options.interpolationPrefix + 'lng' + options.interpolationSuffix), 'g'), | ||
'ns': new RegExp(_.escapeRegExp(options.interpolationPrefix + 'ns' + options.interpolationSuffix), 'g') | ||
}; | ||
return options.resGetPath | ||
.replace(regex.lng, lng) | ||
.replace(regex.ns, ns); | ||
}, | ||
debuglog: function() { | ||
var debug = !!that.options.debug; | ||
if (debug) { | ||
var options = that.options; | ||
if (!!options.debug) { | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
@@ -65,6 +79,2 @@ console.log.apply(this, args); | ||
_.defaults(this.options, defaults); | ||
options = this.options; | ||
if (_.isString(options.ns)) { | ||
@@ -90,9 +100,3 @@ options.ns = { | ||
_.each(options.ns.namespaces, function(ns) { | ||
var regex = { | ||
'lng': new RegExp(_.escapeRegExp(options.interpolationPrefix + 'lng' + options.interpolationSuffix), 'g'), | ||
'ns': new RegExp(_.escapeRegExp(options.interpolationPrefix + 'ns' + options.interpolationSuffix), 'g') | ||
}; | ||
var resPath = options.resGetPath | ||
.replace(regex.lng, lng) | ||
.replace(regex.ns, ns); | ||
var resPath = fn.getResourcePath(lng, ns); | ||
@@ -113,6 +117,6 @@ resStore[lng][ns] = {}; | ||
fn.debuglog({ | ||
options: options, | ||
resStore: resStore | ||
}); | ||
fn.debuglog('parser initialization:', JSON.stringify({ | ||
'options': options, | ||
'resStore': resStore | ||
}, null, 2)); | ||
}; | ||
@@ -150,6 +154,11 @@ | ||
if ( ! _.isUndefined(value)) { | ||
// Reuse the key existed in the resStore | ||
// Found a value associated with the key | ||
lookupKey = '[' + lng + '][' + ns + '][' + keys.join('][') + ']'; | ||
fn.debuglog('[v] resStore' + lookupKey + '="' + map(resStore, lookupKey) + '"'); | ||
fn.debuglog('Found a value %s associated with the key %s in %s.', | ||
JSON.stringify(map(resStore, lookupKey)), | ||
JSON.stringify(keys.join(options.keyseparator)), | ||
JSON.stringify(fn.getResourcePath(lng, ns)) | ||
); | ||
} else if (_.isObject(resStore[lng][ns])) { | ||
// Adding a new entry | ||
var res = resStore[lng][ns]; | ||
@@ -165,5 +174,8 @@ _.each(keys, function(elem, index) { | ||
// Add new key to the resStore | ||
lookupKey = '[' + lng + '][' + ns + '][' + keys.join('][') + ']'; | ||
fn.debuglog('[+] resStore' + lookupKey + '="' + map(resStore, lookupKey) + '"'); | ||
fn.debuglog('Adding a new entry {%s:%s} to %s.', | ||
JSON.stringify(keys.join(options.keyseparator)), | ||
JSON.stringify(map(resStore, lookupKey)), | ||
JSON.stringify(fn.getResourcePath(lng, ns)) | ||
); | ||
} else { // skip the namespace that is not defined in the i18next options | ||
@@ -170,0 +182,0 @@ var msg = 'Please ensure the namespace "' + ns + '" exists in the ns.namespaces[] of your ' + pkg.name + ' options: ' + JSON.stringify({ |
{ | ||
"name": "i18next-scanner", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "i18next-scanner is a transfrom stream that can scan your code, extract translation keys/values, and merge them into i18n resource files.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/cheton/i18next-scanner", |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
48188
876
0