diff --git a/package.json b/package.json index a844167f5..2d1c3f626 100644 --- a/package.json +++ b/package.json @@ -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;", diff --git a/scripts/translations/find-duplicate-translations.js b/scripts/translations/find-duplicate-translations.js new file mode 100644 index 000000000..f8b25497c --- /dev/null +++ b/scripts/translations/find-duplicate-translations.js @@ -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 + + diff --git a/scripts/lint-translations.js b/scripts/translations/lint-translations.js similarity index 100% rename from scripts/lint-translations.js rename to scripts/translations/lint-translations.js diff --git a/scripts/unused-translations.js b/scripts/translations/unused-translations.js similarity index 100% rename from scripts/unused-translations.js rename to scripts/translations/unused-translations.js