Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i18next-scanner

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-scanner - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

16

lib/parser.js

@@ -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 @@

2

package.json
{
"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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc