Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed May 20, 2016
2 parents 9bb697e + faec700 commit a63bbf0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "i18next-scanner",
"version": "1.3.0",
"version": "1.3.1",
"description": "Scan your code, extract translation keys/values, and merge them into i18n resource files.",
"homepage": "https://github.com/i18next/i18next-scanner",
"author": "Cheton Wu <cheton@gmail.com>",
Expand Down
4 changes: 2 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,9 @@ class Parser {
// @param {string|number} [options.space] The same as the JSON.stringify() method
// @return {string}
toJSON(options = {}) {
const { replacer, space } = options;
const { replacer, space, ...others } = options;

return JSON.stringify(this.getResourceStore(options), replacer, space);
return JSON.stringify(this.get(others), replacer, space);
}
}

Expand Down
58 changes: 58 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ import { Parser } from '../src';

const defaults = {};

test('skip undefined namespace', (t) => {
const parser = new Parser({
ns: ['translation']
});
const content = `
i18next.t('none:key2');
i18next.t('key1');
`;
const wanted = {
en: {
translation: {
key1: ''
}
}
};

parser.parseFuncFromString(content);
t.same(parser.get(), wanted);
t.end();
});

test('parse translation function', (t) => {
const parser = new Parser({
lngs: ['en'],
Expand Down Expand Up @@ -264,3 +285,40 @@ test('Context with plural combined', (t) => {
});
t.end();
});

test('parser.toJSON()', (t) => {
const parser = new Parser();
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/app.js'), 'utf-8');

parser.parseFuncFromString(content);

t.same(parser.toJSON(), '{"en":{"translation":{"key2":"","key1":""}}}');
t.end();
});

test('parser.toJSON({ sort: true })', (t) => {
const parser = new Parser();
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/app.js'), 'utf-8');

parser.parseFuncFromString(content);

t.same(parser.toJSON({ sort: true }), '{"en":{"translation":{"key1":"","key2":""}}}');
t.end();
});

test('parser.toJSON({ sort: true, space: 2 })', (t) => {
const parser = new Parser();
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/app.js'), 'utf-8');
const wanted = JSON.stringify({
en: {
translation: {
key1: '',
key2: ''
}
}
}, null, 2);

parser.parseFuncFromString(content);
t.same(parser.toJSON({ sort: true, space: 2 }), wanted);
t.end();
});

0 comments on commit a63bbf0

Please sign in to comment.