habitica/test/sanity/no-duplicate-translation-keys.js

26 lines
718 B
JavaScript
Raw Permalink Normal View History

2020-07-01 16:20:18 +00:00
import { sync as glob } from 'glob';
describe('Locales files', () => {
it('do not contain duplicates of any keys', () => {
2019-10-08 18:45:38 +00:00
const translationFiles = glob('./website/common/locales/en/*.json');
if (translationFiles.length === 0) {
throw new Error('Could not find any files in ./website/common/locales/en/*.json');
}
2019-10-08 18:45:38 +00:00
const keys = {};
2019-10-08 18:45:38 +00:00
translationFiles.forEach(file => {
const json = require(`../.${file}`); // eslint-disable-line global-require, import/no-dynamic-require
2019-10-08 18:45:38 +00:00
Object.keys(json).forEach(key => {
if (keys[key]) {
throw new Error(`${key} in ${file} already exists in ${keys[key]}.`);
}
keys[key] = file;
});
});
});
});