Skip to content

Commit

Permalink
#676 Ensure translations have the same number of format tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ro31337 committed Dec 26, 2017
1 parent 5106ca6 commit 2988cba
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,5 @@
* Add tests to ensure submitted translations have the same number of format tags.

Fixes #679.

*Roman Pushkin*
33 changes: 33 additions & 0 deletions test/i18n-test.js
Expand Up @@ -155,3 +155,36 @@ test.cb('locales should not have long keys with {{phone}}', t => {
t.end();
});
});

test.cb('all translations should have the same number of format tags', t => {
t.plan(NUM_OF_LOCALIZATIONS - 1);
const walker = walk.walk('../locales', { followLinks: false });
const en = require('../locales/en.json'); // eslint-disable-line global-require

// walk through each file, except en.json
walker.on('file', (root, stat, next) => {
if (stat.name !== 'en.json') {
const path = `${root}/${stat.name}`;
const xx = require(path); // eslint-disable-line global-require

for (const key of Object.keys(en)) {
if (key.endsWith('_desc')) continue;
const cnt1 = (en[key].match(/%/g) || []).length;
const cnt2 = (xx[key].match(/%/g) || []).length;

if (cnt1 !== cnt2) {
t.fail(`Key '${key}' in en.json has ${cnt1} format tag(s) (%), ` +
`but in ${stat.name} it is ${cnt2}. Number of format tags should be the same.`);
}
}

t.pass();
}

next();
});

walker.on('end', () => {
t.end();
});
});

0 comments on commit 2988cba

Please sign in to comment.