Socket
Socket
Sign inDemoInstall

i18next-scanner

Package Overview
Dependencies
Maintainers
1
Versions
92
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 1.0.2 to 1.1.0

6

lib/parser.js

@@ -413,6 +413,6 @@ 'use strict';

if (index >= keys.length - 1) {
if (options.keySeparator === false) {
res[elem] = elem;
if (_lodash2.default.isUndefined(defaultValue)) {
res[elem] = _lodash2.default.isFunction(options.defaultValue) ? options.defaultValue(lng, ns, elem) : options.defaultValue;
} else {
res[elem] = _lodash2.default.isUndefined(defaultValue) ? options.defaultValue : defaultValue;
res[elem] = defaultValue;
}

@@ -419,0 +419,0 @@ } else {

{
"name": "i18next-scanner",
"version": "1.0.2",
"version": "1.1.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",

@@ -403,6 +403,32 @@ # 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: `String` Default: `''`
Type: `String` or `Function` Default: `''`
The default value used if not passed to `parser.set`.
##### Examples
Provides the default value with a string:
```js
{
defaultValue: '__NOT_TRANSLATED__'
}
```
Provides the default value with a function:
```js
{
// @param {string} lng The language currently used.
// @param {ns} ns The namespace currently used.
// @param {key} key The translation key.
// @return {string} Returns a default value for the translation key.
defaultValue: function(lng, ns, key) {
if (lng === 'en') {
// Return key as the default value for English language
return key;
}
// Return the string '__NOT_TRANSLATED__' for other languages
return '__NOT_TRANSLATED__';
}
}
```
#### resource

@@ -417,3 +443,3 @@

// path where resources get loaded from
savePath: 'i18n/{{lng}}/{{ns}}.json',
loadPath: 'i18n/{{lng}}/{{ns}}.json',

@@ -420,0 +446,0 @@ // path to store resources

@@ -367,6 +367,6 @@ /* eslint no-console: 0 */

if (index >= (keys.length - 1)) {
if (options.keySeparator === false) {
res[elem] = elem;
if (_.isUndefined(defaultValue)) {
res[elem] = _.isFunction(options.defaultValue) ? options.defaultValue(lng, ns, elem) : options.defaultValue;
} else {
res[elem] = _.isUndefined(defaultValue) ? options.defaultValue : defaultValue;
res[elem] = defaultValue;
}

@@ -373,0 +373,0 @@ } else {

@@ -33,3 +33,3 @@ import _ from 'lodash';

test('should get expected result', function(t) {
test('[Key Based Fallback] defaultValue as string', function(t) {
const options = _.merge({}, defaults, {

@@ -53,2 +53,35 @@ func: {

const wanted = {
"Loading...": "__STRING_NOT_TRANSLATED__",
"This value does not exist.": "__STRING_NOT_TRANSLATED__",
"YouTube has more than __count__ billion users.": "__STRING_NOT_TRANSLATED__"
};
t.same(found, wanted);
}
}))
.on('end', function() {
t.end();
});
});
test('[Key Based Fallback] defaultValue as function', function(t) {
const options = _.merge({}, defaults, {
defaultValue: function(lng, ns, key) {
if (lng === 'en') {
return key;
}
return '__STRING_NOT_TRANSLATED__';
},
func: {
extensions: ['.js'] // with extensions
}
});
gulp.src('test/fixtures/modules/**/*.js')
.pipe(scanner(options))
.pipe(tap(function(file) {
const contents = file.contents.toString();
if (file.path === 'i18n/en/resource.json') {
const found = JSON.parse(contents);
const wanted = {
"Loading...": "Loading...",

@@ -60,2 +93,12 @@ "This value does not exist.": "This value does not exist.",

}
if (file.path === 'i18n/de/resource.json') {
const found = JSON.parse(contents);
const wanted = {
"Loading...": "__STRING_NOT_TRANSLATED__",
"This value does not exist.": "__STRING_NOT_TRANSLATED__",
"YouTube has more than __count__ billion users.": "__STRING_NOT_TRANSLATED__"
};
t.same(found, wanted);
}
}))

@@ -62,0 +105,0 @@ .on('end', function() {

@@ -98,2 +98,5 @@ import fs from 'fs';

const parser = new Parser({
defaultValue: (lng, ns, key) => {
return key;
},
keySeparator: false,

@@ -122,7 +125,8 @@ nsSeparator: false

test('disable nsSeparator', (t) => {
const parser = new Parser(Object.assign({}, defaults, {
const parser = new Parser({
defaultValue: '__NOT_TRANSLATED__',
nsSeparator: false,
keySeparator: '.'
}));
parser.set('foo:bar', '');
});
parser.set('foo:bar');

@@ -134,3 +138,3 @@ const resStore = parser.get();

translation: {
'foo:bar': ''
'foo:bar': '__NOT_TRANSLATED__'
}

@@ -143,7 +147,8 @@ }

test('disable keySeparator', (t) => {
const parser = new Parser(Object.assign({}, defaults, {
const parser = new Parser({
defaultValue: '__NOT_TRANSLATED__',
nsSeparator: ':',
keySeparator: false
}));
parser.set('Creating...', '');
});
parser.set('Creating...');

@@ -155,3 +160,3 @@ const resStore = parser.get();

translation: {
'Creating...': 'Creating...'
'Creating...': '__NOT_TRANSLATED__'
}

@@ -164,7 +169,8 @@ }

test('default nsSeparator', (t) => {
const parser = new Parser(Object.assign({}, defaults, {
const parser = new Parser({
defaultValue: '__NOT_TRANSLATED__',
nsSeparator: ':',
keySeparator: '.'
}));
parser.set('translation:key1.key2', '');
});
parser.set('translation:key1.key2');

@@ -177,3 +183,3 @@ const resStore = parser.get();

'key1': {
'key2': ''
'key2': '__NOT_TRANSLATED__'
}

@@ -187,7 +193,8 @@ }

test('default keyseparator', (t) => {
const parser = new Parser(Object.assign({}, defaults, {
const parser = new Parser({
defaultValue: '__NOT_TRANSLATED__',
nsSeparator: ':',
keySeparator: '.'
}));
parser.set('key1.key2', '');
});
parser.set('key1.key2');

@@ -200,3 +207,3 @@ const resStore = parser.get();

'key1': {
'key2': ''
'key2': '__NOT_TRANSLATED__'
}

@@ -203,0 +210,0 @@ }

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