i18next-scanner
Advanced tools
Comparing version 3.2.0 to 3.3.0
@@ -165,3 +165,5 @@ "use strict"; | ||
}, | ||
metadata: {} // additional custom options | ||
metadata: {}, | ||
// additional custom options | ||
allowDynamicKeys: false // allow Dynamic Keys | ||
@@ -427,9 +429,17 @@ }; // http://codereview.stackexchange.com/questions/45991/balanced-parentheses | ||
value: function fixStringAfterRegExp(strToFix) { | ||
var options = this.options; | ||
var fixedString = _lodash["default"].trim(strToFix); // Remove leading and trailing whitespace | ||
var firstChar = fixedString[0]; // Ignore key with embedded expressions in string literals | ||
var firstChar = fixedString[0]; | ||
if (firstChar === '`' && fixedString.match(/\${.*?}/)) { | ||
return null; | ||
if (options.allowDynamicKeys && fixedString.endsWith('}`')) { | ||
// Allow Dyanmic Keys at the end of the string literal with option enabled | ||
fixedString = fixedString.replace(/\$\{(.+?)\}/g, ''); | ||
} else { | ||
// Ignore key with embedded expressions in string literals | ||
return null; | ||
} | ||
} | ||
@@ -436,0 +446,0 @@ |
{ | ||
"name": "i18next-scanner", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"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", |
@@ -831,4 +831,57 @@ # 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) | ||
#### allowDynamicKeys | ||
Type: `Boolean` Default: `false` | ||
This can be used to allow dynamic keys e.g. `friend${DynamicValue}` | ||
Example Usage: | ||
``` | ||
transform: function customTransform(file, enc, done) { | ||
'use strict'; | ||
const parser = this.parser; | ||
const contexts = { | ||
compact: ['compact'], | ||
max: ['Max'], | ||
}; | ||
const keys = { | ||
difficulty: { list: ['Normal', 'Hard'] }, | ||
minMax: { list: ['Min', 'Max'] }, | ||
}; | ||
const content = fs.readFileSync(file.path, enc); | ||
parser.parseFuncFromString(content, { list: ['i18next.t', 'i18n.t'] }, (key, options) => { | ||
// Add context based on metadata | ||
if (options.metadata?.context) { | ||
delete options.context; | ||
const context = contexts[options.metadata?.context]; | ||
parser.set(key, options); | ||
for (let i = 0; i < context?.length; i++) { | ||
parser.set(`${key}${parser.options.contextSeparator}${context[i]}`, options); | ||
} | ||
} | ||
// Add keys based on metadata (dynamic or otherwise) | ||
if (options.metadata?.keys) { | ||
const list = keys[options.metadata?.keys].list; | ||
for (let i = 0; i < list?.length; i++) { | ||
parser.set(`${key}${list[i]}`, options); | ||
} | ||
} | ||
// Add all other non-metadata related keys | ||
if (!options.metadata) { | ||
parser.set(key, options); | ||
} | ||
}); | ||
done(); | ||
``` | ||
## License | ||
MIT |
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
90863
1313
887