mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-30 10:58:23 -05:00
e1a0e9fece
* Don’t allow duplicate strings in a single l10n file Added check_duplicate_strings to test for duplicates in a single file. removed duplicates - tried to keep the more generic ‘key’ * revised test case for safer file reads
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
/*
|
|
* Check that there are no duplicate strings in any individual l10n json file.
|
|
*/
|
|
var path = require('path');
|
|
var fs = require('fs');
|
|
var tap = require('tap');
|
|
|
|
var routes = require('../../src/routes.json');
|
|
|
|
function noDuplicateValues (idsToCheck, name) {
|
|
var values = {};
|
|
for (var key in idsToCheck) {
|
|
if (values.hasOwnProperty(idsToCheck[key])) {
|
|
// duplicate values
|
|
//return false;
|
|
tap.fail(name + '.' + idsToCheck[key] + ' has duplicates');
|
|
} else {
|
|
values[idsToCheck[key]] = key;
|
|
}
|
|
}
|
|
tap.pass();
|
|
//return true;
|
|
}
|
|
|
|
tap.test('generalCheckForDuplicates', function (t) {
|
|
var ids = require(path.resolve(__dirname, '../../src/l10n.json'));
|
|
noDuplicateValues(ids, 'general');
|
|
t.end();
|
|
});
|
|
|
|
for (var v in routes) {
|
|
if (typeof routes[v].redirect !== 'undefined') {
|
|
continue;
|
|
}
|
|
var subdir = routes[v].view.split('/');
|
|
subdir.pop();
|
|
var name = routes[v].name;
|
|
var uri = path.resolve(__dirname, '../../src/views/' + subdir.join('/') +'/l10n.json');
|
|
try {
|
|
var file = fs.readFileSync(uri, 'utf8');
|
|
var ids = JSON.parse(file);
|
|
tap.test(name + 'CheckForDuplicates', function (t) {
|
|
noDuplicateValues(ids, name);
|
|
t.end();
|
|
});
|
|
} catch (err) {
|
|
if (err.code !== 'ENOENT') {
|
|
// ignore if ENOENT for routes with no l10n file, throw error for anything else
|
|
throw err;
|
|
}
|
|
}
|
|
}
|