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

i18next-parser

Package Overview
Dependencies
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-parser - npm Package Compare versions

Comparing version 1.0.0-beta36 to 1.0.0-beta37

22

bin/cli.js

@@ -14,3 +14,3 @@ #!/usr/bin/env node

.version(pkg.version)
.option('-c, --config <path>', 'Path to the config file (default: i18next-parser.config.js)')
.option('-c, --config <path>', 'Path to the config file (default: i18next-parser.config.js)', 'i18next-parser.config.js')
.option('-o, --output <path>', 'Path to the output directory (default: locales/$LOCALE/$NAMESPACE.json)')

@@ -31,12 +31,10 @@ .option('-s, --silent', 'Disable logging to stdout')

var config = {}
if (program.config) {
try {
config = require(path.resolve(program.config))
} catch (err) {
console.log(' [error] '.red + 'Config file does not exist: ' + program.config)
return
}
try {
config = require(path.resolve(program.config))
} catch (err) {
console.log(' [error] '.red + 'Config file does not exist: ' + program.config)
return
}
config.output = program.output || config.output
config.output = program.output || config.output || 'locales/$LOCALE/$NAMESPACE.json'

@@ -75,8 +73,2 @@ var args = program.args || []

if (!config.output) {
console.log(' [error] '.red + 'an `output` is required via --config or --output option')
program.help()
program.exit(1)
}
if (!globs.length) {

@@ -83,0 +75,0 @@ console.log(' [error] '.red + 'missing argument: ')

@@ -11,2 +11,6 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;}; /**

var path = entry.key;
if (options.suffix || options.suffix === 0) {
path += '_' + options.suffix;
}
var separator = options.separator || '.';

@@ -93,3 +97,3 @@ var newValue = entry.defaultValue || options.value || '';

// support for plural in keys
var pluralRegex = /_plural(_\d+)?$/;
var pluralRegex = /(_plural)|(_\d+)$/;
var pluralMatch = pluralRegex.test(key);

@@ -96,0 +100,0 @@ var singularKey = key.replace(pluralRegex, '');

@@ -73,3 +73,3 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _baseLexer = require('./base-lexer');var _baseLexer2 = _interopRequireDefault(_baseLexer);

for (var _iterator = optionsArgument.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var p = _step.value;
entry[p.name.text] = p.initializer.text;
entry[p.name.text] = p.initializer && p.initializer.text || '';
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator.return) {_iterator.return();}} finally {if (_didIteratorError) {throw _iteratorError;}}}

@@ -76,0 +76,0 @@ }

@@ -9,6 +9,16 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _helpers = require('./helpers');

var _yamljs = require('yamljs');var _yamljs2 = _interopRequireDefault(_yamljs);
var _baseLexer = require('./lexers/base-lexer');var _baseLexer2 = _interopRequireDefault(_baseLexer);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;}
var _baseLexer = require('./lexers/base-lexer');var _baseLexer2 = _interopRequireDefault(_baseLexer);
var _i18next = require('i18next');var _i18next2 = _interopRequireDefault(_i18next);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;}
function warn() {var _console;for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
(_console = console).warn.apply(_console, ['\x1b[33m%s\x1b[0m'].concat(args));
}
function getPluralSuffix(numberOfPluralForms, nthForm) {
if (numberOfPluralForms.length > 2) {
return nthForm; // key_0, key_1, etc.
} else if (nthForm === 1) {
return 'plural';
}
return '';
}var

@@ -54,3 +64,5 @@

_this.localeRegex = /\$LOCALE/g;
_this.namespaceRegex = /\$NAMESPACE/g;return _this;
_this.namespaceRegex = /\$NAMESPACE/g;
_i18next2.default.init();return _this;
}_createClass(i18nTransform, [{ key: '_transform', value: function _transform(

@@ -103,11 +115,15 @@

done) {
var catalog = {};
done) {var _this2 = this;
if (this.options.sort) {
this.entries = this.entries.sort(function (a, b) {return a.key.localeCompare(b.key);});
}
}var _loop = function _loop(
var uniqueCount = this.entries.length;var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try {
for (var _iterator2 = this.entries[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var entry = _step2.value;var _dotPathToHash =
locale) {
var catalog = {};var _i18next$services$plu =
_i18next2.default.services.pluralResolver.getRule(locale),numbers = _i18next$services$plu.numbers;
var countWithPlurals = 0;
var uniqueCount = _this2.entries.length;
var transformEntry = function transformEntry(entry, suffix) {var _dotPathToHash =
(0, _helpers.dotPathToHash)(

@@ -117,7 +133,9 @@ entry,

{
separator: this.options.keySeparator,
value: this.options.defaultValue,
useKeysAsDefaultValue: this.options.useKeysAsDefaultValue }),duplicate = _dotPathToHash.duplicate,conflict = _dotPathToHash.conflict;
suffix: suffix,
separator: _this2.options.keySeparator,
value: _this2.options.defaultValue,
useKeysAsDefaultValue: _this2.options.useKeysAsDefaultValue }),duplicate = _dotPathToHash.duplicate,conflict = _dotPathToHash.conflict;
if (duplicate) {

@@ -127,66 +145,76 @@ uniqueCount -= 1;

var warning = 'Found same keys with different values: ' + entry.key;
this.emit('warning', warning);
if (this.options.verbose) {
_this2.emit('warning', warning);
if (_this2.options.verbose) {
warn(warning);
}
}
} else {
countWithPlurals += 1;
}
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2.return) {_iterator2.return();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}}
if (this.options.verbose) {
console.log('\nParsed keys: ' + uniqueCount + '\n');
}var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try {
};
for (var _iterator3 = this.options.locales[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var locale = _step3.value;
var outputPath = _path2.default.resolve(this.options.output);
// generates plurals according to i18next rules: key, key_plural, key_0, key_1, etc.
var _loop2 = function _loop2(entry) {
if (entry.count !== undefined) {
numbers.forEach(function (_, i) {
transformEntry(entry, getPluralSuffix(numbers, i));
});
} else {
transformEntry(entry);
}};var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try {for (var _iterator3 = _this2.entries[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var entry = _step3.value;_loop2(entry);
}} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3.return) {_iterator3.return();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}}
for (var namespace in catalog) {
var namespacePath = outputPath;
namespacePath = namespacePath.replace(this.localeRegex, locale);
namespacePath = namespacePath.replace(this.namespaceRegex, namespace);
var outputPath = _path2.default.resolve(_this2.options.output);
var parsedNamespacePath = _path2.default.parse(namespacePath);
for (var namespace in catalog) {
var namespacePath = outputPath;
namespacePath = namespacePath.replace(_this2.localeRegex, locale);
namespacePath = namespacePath.replace(_this2.namespaceRegex, namespace);
var namespaceOldPath = _path2.default.join(parsedNamespacePath.dir, parsedNamespacePath.name + '_old' + parsedNamespacePath.ext);
var parsedNamespacePath = _path2.default.parse(namespacePath);
var existingCatalog = this.getCatalog(namespacePath);
var existingOldCatalog = this.getCatalog(namespaceOldPath);
var namespaceOldPath = _path2.default.join(parsedNamespacePath.dir, parsedNamespacePath.name + '_old' + parsedNamespacePath.ext);
// merges existing translations with the new ones
var _mergeHashes =
(0, _helpers.mergeHashes)(
existingCatalog,
catalog[namespace],
this.options.keepRemoved),newCatalog = _mergeHashes.new,oldKeys = _mergeHashes.old,mergeCount = _mergeHashes.mergeCount,oldCount = _mergeHashes.oldCount;
var existingCatalog = _this2.getCatalog(namespacePath);
var existingOldCatalog = _this2.getCatalog(namespaceOldPath);
// merges existing translations with the new ones
var _mergeHashes =
(0, _helpers.mergeHashes)(
existingCatalog,
catalog[namespace],
_this2.options.keepRemoved),newCatalog = _mergeHashes.new,oldKeys = _mergeHashes.old,mergeCount = _mergeHashes.mergeCount,oldCount = _mergeHashes.oldCount;
// restore old translations
var _mergeHashes2 = (0, _helpers.mergeHashes)(existingOldCatalog, newCatalog),oldCatalog = _mergeHashes2.old,restoreCount = _mergeHashes2.mergeCount;
// backup unused translations
(0, _helpers.transferValues)(oldKeys, oldCatalog);
// restore old translations
var _mergeHashes2 = (0, _helpers.mergeHashes)(existingOldCatalog, newCatalog),oldCatalog = _mergeHashes2.old,restoreCount = _mergeHashes2.mergeCount;
if (this.options.verbose) {
console.log('[' + locale + '] ' + namespace + '\n');
var addCount = uniqueCount - mergeCount;
console.log('Added keys: ' + addCount);
console.log('Restored keys: ' + restoreCount);
if (this.options.keepRemoved) {
console.log('Unreferenced keys: ' + oldCount);
} else {
console.log('Removed keys: ' + oldCount);
}
console.log();
}
// backup unused translations
(0, _helpers.transferValues)(oldKeys, oldCatalog);
// push files back to the stream
this.pushFile(namespacePath, newCatalog);
if (
this.options.createOldCatalogs && (
Object.keys(oldCatalog).length || existingOldCatalog))
{
this.pushFile(namespaceOldPath, oldCatalog);
if (_this2.options.verbose) {
console.log('[' + locale + '] ' + namespace + '\n');
console.log('Unique keys: ' + uniqueCount + ' (' + countWithPlurals + ' with plurals)');
var addCount = countWithPlurals - mergeCount;
console.log('Added keys: ' + addCount);
console.log('Restored keys: ' + restoreCount);
if (_this2.options.keepRemoved) {
console.log('Unreferenced keys: ' + oldCount);
} else {
console.log('Removed keys: ' + oldCount);
}
console.log();
}
}} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3.return) {_iterator3.return();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}}
// push files back to the stream
_this2.pushFile(namespacePath, newCatalog);
if (
_this2.options.createOldCatalogs && (
Object.keys(oldCatalog).length || existingOldCatalog))
{
_this2.pushFile(namespaceOldPath, oldCatalog);
}
}};var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try {for (var _iterator2 = this.options.locales[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var locale = _step2.value;_loop(locale);
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2.return) {_iterator2.return();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}}
done();

@@ -201,3 +229,2 @@ } }, { key: 'addEntry', value: function addEntry(

this.entries.push(contextEntry);
// this.addEntry(contextEntry)
} else

@@ -204,0 +231,0 @@ {

@@ -5,3 +5,3 @@ {

"name": "i18next-parser",
"version": "1.0.0-beta36",
"version": "1.0.0-beta37",
"license": "MIT",

@@ -29,2 +29,3 @@ "main": "dist/index.js",

"gulp-sort": "^2.0.0",
"i18next": "^19.0.1",
"rsvp": "^4.8.2",

@@ -31,0 +32,0 @@ "through2": "~2.0.3",

@@ -24,3 +24,3 @@ # i18next Parser [![Build Status](https://travis-ci.org/i18next/i18next-parser.svg?branch=master)](https://travis-ci.org/i18next/i18next-parser)

- **Context**: keys of the form `key_context`
- **Plural**: keys of the form `key_plural` and `key_plural_0`
- **Plural**: keys of the form `key_plural` and `key_0`, `key_1` as described [here](https://www.i18next.com/translation-function/plurals)
- Tested on Node 6+

@@ -354,2 +354,2 @@

</a>
</p>
</p>

@@ -11,2 +11,6 @@ /**

let path = entry.key
if (options.suffix || options.suffix === 0) {
path += `_${options.suffix}`
}
const separator = options.separator || '.'

@@ -93,3 +97,3 @@ let newValue = entry.defaultValue || options.value || ''

// support for plural in keys
const pluralRegex = /_plural(_\d+)?$/;
const pluralRegex = /(_plural)|(_\d+)$/;
const pluralMatch = pluralRegex.test(key)

@@ -96,0 +100,0 @@ const singularKey = key.replace(pluralRegex, '')

@@ -14,3 +14,3 @@ import BaseLexer from './base-lexer'

const keys = []
const parseTree = (node) => {

@@ -22,3 +22,3 @@ let entry

}
if (entry) {

@@ -30,3 +30,3 @@ keys.push(entry)

}
const sourceFile = ts.createSourceFile(filename, content, ts.ScriptTarget.Latest)

@@ -41,7 +41,7 @@ parseTree(sourceFile)

const isTranslationFunction =
(node.expression.text && this.functions.includes(node.expression.text)) ||
const isTranslationFunction =
(node.expression.text && this.functions.includes(node.expression.text)) ||
(node.expression.name && this.functions.includes(node.expression.name.text))
if (isTranslationFunction) {

@@ -77,3 +77,3 @@ const keyArgument = node.arguments.shift()

for (const p of optionsArgument.properties) {
entry[p.name.text] = p.initializer.text
entry[p.name.text] = p.initializer && p.initializer.text || ''
}

@@ -80,0 +80,0 @@ }

@@ -10,2 +10,3 @@ import { dotPathToHash, mergeHashes, transferValues } from './helpers'

import BaseLexer from './lexers/base-lexer'
import i18next from 'i18next'

@@ -16,2 +17,11 @@ function warn(...args) {

function getPluralSuffix(numberOfPluralForms, nthForm) {
if (numberOfPluralForms.length > 2) {
return nthForm // key_0, key_1, etc.
} else if (nthForm === 1) {
return 'plural'
}
return ''
}
export default class i18nTransform extends Transform {

@@ -56,2 +66,4 @@ constructor(options = {}) {

this.namespaceRegex = /\$NAMESPACE/g
i18next.init();
}

@@ -105,4 +117,2 @@

_flush(done) {
let catalog = {}
if (this.options.sort) {

@@ -112,29 +122,46 @@ this.entries = this.entries.sort((a, b) => a.key.localeCompare(b.key))

let uniqueCount = this.entries.length
for (const entry of this.entries) {
const { duplicate, conflict } = dotPathToHash(
entry,
catalog,
{
separator: this.options.keySeparator,
value: this.options.defaultValue,
useKeysAsDefaultValue: this.options.useKeysAsDefaultValue
}
)
if (duplicate) {
uniqueCount -= 1
if (conflict) {
const warning = `Found same keys with different values: ${entry.key}`
this.emit('warning', warning)
if (this.options.verbose) {
warn(warning)
for (const locale of this.options.locales) {
const catalog = {}
const { numbers } = i18next.services.pluralResolver.getRule(locale)
let countWithPlurals = 0
let uniqueCount = this.entries.length
const transformEntry = (entry, suffix) => {
const { duplicate, conflict } = dotPathToHash(
entry,
catalog,
{
suffix,
separator: this.options.keySeparator,
value: this.options.defaultValue,
useKeysAsDefaultValue: this.options.useKeysAsDefaultValue
}
)
if (duplicate) {
uniqueCount -= 1
if (conflict) {
const warning = `Found same keys with different values: ${entry.key}`
this.emit('warning', warning)
if (this.options.verbose) {
warn(warning)
}
}
} else {
countWithPlurals += 1
}
}
}
if (this.options.verbose) {
console.log(`\nParsed keys: ${uniqueCount}\n`)
}
for (const locale of this.options.locales) {
// generates plurals according to i18next rules: key, key_plural, key_0, key_1, etc.
for (const entry of this.entries) {
if (entry.count !== undefined) {
numbers.forEach((_, i) => {
transformEntry(entry, getPluralSuffix(numbers, i))
})
} else {
transformEntry(entry)
}
}
const outputPath = path.resolve(this.options.output)

@@ -157,6 +184,6 @@

mergeHashes(
existingCatalog,
catalog[namespace],
this.options.keepRemoved
)
existingCatalog,
catalog[namespace],
this.options.keepRemoved
)

@@ -171,3 +198,4 @@ // restore old translations

console.log(`[${locale}] ${namespace}\n`)
const addCount = uniqueCount - mergeCount
console.log(`Unique keys: ${uniqueCount} (${countWithPlurals} with plurals)`)
const addCount = countWithPlurals - mergeCount
console.log(`Added keys: ${addCount}`)

@@ -203,3 +231,2 @@ console.log(`Restored keys: ${restoreCount}`)

this.entries.push(contextEntry)
// this.addEntry(contextEntry)
}

@@ -206,0 +233,0 @@ else {

@@ -5,4 +5,4 @@ {

"second": "second",
"second_plural_0": "second plural 0",
"second_plural_12": "second plural 12"
"second_0": "second plural 0",
"second_12": "second plural 12"
}

@@ -8,2 +8,3 @@ import { assert } from 'chai'

const enLibraryPath = path.normalize('en/translation.json')
const arLibraryPath = path.normalize('ar/translation.json')

@@ -500,4 +501,4 @@ describe('parser', () => {

second: 'second',
second_plural_0: 'second plural 0',
second_plural_12: 'second plural 12'
second_0: 'second plural 0',
second_12: 'second plural 12'
}

@@ -529,3 +530,2 @@

first_context1_plural: 'first context1 plural',
first_context2_plural_2: 'first context2 plural 2'
}

@@ -778,4 +778,4 @@

})
it('supports outputing to yml', (done) => {

@@ -903,5 +903,5 @@ let result

i18nextParser.on('end', () => {
assert.deepEqual(result, {
first: 'first',
'second and third': 'second and third',
assert.deepEqual(result, {
first: 'first',
'second and third': 'second and third',
'$fourth %fifth%': '$fourth %fifth%',

@@ -917,2 +917,111 @@ six: {

it('generates plurals', (done) => {
let result
const i18nextParser = new i18nTransform()
const fakeFile = new Vinyl({
contents: Buffer.from("t('test {{count}}', { count: 1 })"),
path: 'file.js'
})
i18nextParser.on('data', file => {
if (file.relative.endsWith(enLibraryPath)) {
result = JSON.parse(file.contents)
}
})
i18nextParser.once('end', () => {
assert.deepEqual(result, {
'test {{count}}': '',
'test {{count}}_plural': ''
})
done()
})
i18nextParser.end(fakeFile)
})
it('generates plurals for languages with multiple plural forms', (done) => {
let result
const i18nextParser = new i18nTransform({ locales: ['ar'] })
const fakeFile = new Vinyl({
contents: Buffer.from("t('test {{count}}', { count: 1 })"),
path: 'file.js'
})
i18nextParser.on('data', file => {
if (file.relative.endsWith(arLibraryPath)) {
result = JSON.parse(file.contents)
}
})
i18nextParser.once('end', () => {
assert.deepEqual(result, {
'test {{count}}_0': '',
'test {{count}}_1': '',
'test {{count}}_2': '',
'test {{count}}_3': '',
'test {{count}}_4': '',
'test {{count}}_5': '',
})
done()
})
i18nextParser.end(fakeFile)
})
it('generates plurals with key as value', (done) => {
let result
const i18nextParser = new i18nTransform({
useKeysAsDefaultValue: true,
})
const fakeFile = new Vinyl({
contents: Buffer.from("t('test {{count}}', { count: 1 })"),
path: 'file.js'
})
i18nextParser.on('data', file => {
if (file.relative.endsWith(enLibraryPath)) {
result = JSON.parse(file.contents)
}
})
i18nextParser.once('end', () => {
assert.deepEqual(result, {
'test {{count}}': 'test {{count}}',
'test {{count}}_plural': 'test {{count}}'
})
done()
})
i18nextParser.end(fakeFile)
})
it('generates plurals with key as value for languages with multiple plural forms', (done) => {
let result
const i18nextParser = new i18nTransform({
useKeysAsDefaultValue: true,
locales: ['ar']
})
const fakeFile = new Vinyl({
contents: Buffer.from("t('test {{count}}', { count: 1 })"),
path: 'file.js'
})
i18nextParser.on('data', file => {
if (file.relative.endsWith(arLibraryPath)) {
result = JSON.parse(file.contents)
}
})
i18nextParser.once('end', () => {
assert.deepEqual(result, {
'test {{count}}_0': 'test {{count}}',
'test {{count}}_1': 'test {{count}}',
'test {{count}}_2': 'test {{count}}',
'test {{count}}_3': 'test {{count}}',
'test {{count}}_4': 'test {{count}}',
'test {{count}}_5': 'test {{count}}',
})
done()
})
i18nextParser.end(fakeFile)
})
describe('lexers', () => {

@@ -1037,3 +1146,2 @@ it('support custom lexers options', (done) => {

it('emits an `error` if a lexer does not exist', (done) => {
const results = []
const i18nextParser = new i18nTransform({ lexers: { js: ['fakeLexer'] } })

@@ -1040,0 +1148,0 @@ const fakeFile = new Vinyl({

Sorry, the diff of this file is not supported yet

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