add new translation check to find duplicates

and move all translation scripts into a dedicated folder
This commit is contained in:
ansuz 2021-08-23 18:19:35 +05:30
parent 4fe19c1ea4
commit 9f52ec8dc7
4 changed files with 57 additions and 2 deletions

View File

@ -45,8 +45,8 @@
"lint:js": "jshint --config .jshintrc --exclude-path .jshintignore .",
"lint:server": "jshint --config .jshintrc lib",
"lint:less": "./node_modules/lesshint/bin/lesshint -c ./.lesshintrc ./customize.dist/src/less2/",
"lint:translations": "node ./scripts/lint-translations.js",
"unused-translations": "node ./scripts/unused-translations.js",
"lint:translations": "node ./scripts/translations/lint-translations.js",
"unused-translations": "node ./scripts/translations/unused-translations.js",
"test": "node scripts/TestSelenium.js",
"test-rpc": "cd scripts/tests && node test-rpc",
"template": "cd customize.dist/src && for page in ../index.html ../privacy.html ../terms.html ../contact.html ../what-is-cryptpad.html ../features.html ../../www/login/index.html ../../www/register/index.html ../../www/user/index.html;do echo $page; cp template.html $page; done;",

View File

@ -0,0 +1,55 @@
var Util = require("../lib/common-util");
var EN = Util.clone(require("../www/common/translations/messages.json"));
var FR = Util.clone(require("../www/common/translations/messages.fr.json"));
var DE = Util.clone(require("../www/common/translations/messages.de.json"));
var JP = Util.clone(require("../www/common/translations/messages.ja.json"));
var keys = Object.keys(EN);
var duplicates = {};
var addIfAbsent = function (A, e) {
if (A.includes(e)) { return; }
A.push(e);
};
var markDuplicate = function (value, key1, key2) {
//console.log("[%s] === [%s] (%s)", key1, key2, value);
if (!Array.isArray(duplicates[value])) {
duplicates[value] = [];
}
addIfAbsent(duplicates[value], key1);
addIfAbsent(duplicates[value], key2);
};
keys.forEach(function (key) {
var value = EN[key];
//var duplicates = [];
keys.forEach(function (key2) {
if (key === key2) { return; }
var value2 = EN[key2];
if (value === value2) {
markDuplicate(value, key, key2);
}
});
});
// indicate which strings are duplicated and could potentially be changed to use one key
Object.keys(duplicates).forEach(function (val) {
console.log('\"%s\" => %s', val, JSON.stringify(duplicates[val]));
});
// TODO iterate over all languages and
// 1) check whether the same mapping exists across languages
// ie. English has "Open" (verb) and "Open" (adjective)
// while French has "Ouvrir" and "Ouvert(s)"
// such keys should not be simplified/deduplicated
// find instances where
// one of the duplicated keys is not translated
// perhaps we could automatically use the translated one everywhere
// and improve the completeness of translations