Improve assert translations to detect issues in objects (tips, type, etc.)
This commit is contained in:
parent
5bba9b6c39
commit
7ebfa43408
@ -43,7 +43,7 @@ define(req, function(Util, Default, Language) {
|
||||
|
||||
messages._checkTranslationState = function (cb) {
|
||||
if (typeof(cb) !== "function") { return; }
|
||||
var missing = [];
|
||||
var allMissing = [];
|
||||
var reqs = [];
|
||||
Object.keys(map).forEach(function (code) {
|
||||
if (code === defaultLanguage) { return; }
|
||||
@ -54,37 +54,60 @@ define(req, function(Util, Default, Language) {
|
||||
Object.keys(map).forEach(function (code, i) {
|
||||
if (code === defaultLanguage) { return; }
|
||||
var translation = langs[i];
|
||||
var updated = {};
|
||||
Object.keys(Default).forEach(function (k) {
|
||||
if (/^updated_[0-9]+_/.test(k) && !translation[k]) {
|
||||
var key = k.split('_').slice(2).join('_');
|
||||
// Make sure we don't already have an update for that key. It should not happen
|
||||
// but if it does, keep the latest version
|
||||
if (updated[key]) {
|
||||
var ek = updated[key];
|
||||
if (parseInt(ek.split('_')[1]) > parseInt(k.split('_')[1])) { return; }
|
||||
var missing = [];
|
||||
var checkInObject = function (ref, translated, path) {
|
||||
var updated = {};
|
||||
Object.keys(ref).forEach(function (k) {
|
||||
if (/^updated_[0-9]+_/.test(k) && !translated[k]) {
|
||||
var key = k.split('_').slice(2).join('_');
|
||||
// Make sure we don't already have an update for that key. It should not happen
|
||||
// but if it does, keep the latest version
|
||||
if (updated[key]) {
|
||||
var ek = updated[key];
|
||||
if (parseInt(ek.split('_')[1]) > parseInt(k.split('_')[1])) { return; }
|
||||
}
|
||||
updated[key] = k;
|
||||
}
|
||||
updated[key] = k;
|
||||
}
|
||||
});
|
||||
Object.keys(Default).forEach(function (k) {
|
||||
if (/^_/.test(k) || k === 'driveReadme') { return; }
|
||||
if (!translation[k] || updated[k]) {
|
||||
if (updated[k]) {
|
||||
missing.push([code, k, 2, 'out.' + updated[k]]);
|
||||
return;
|
||||
});
|
||||
Object.keys(ref).forEach(function (k) {
|
||||
if (/^_/.test(k) || k === 'driveReadme') { return; }
|
||||
var nPath = path.slice();
|
||||
nPath.push(k);
|
||||
if (!translated[k] || updated[k]) {
|
||||
if (updated[k]) {
|
||||
var uPath = path.slice();
|
||||
uPath.unshift('out');
|
||||
missing.push([code, nPath, 2, uPath.join('.') + '.' + updated[k]]);
|
||||
return;
|
||||
}
|
||||
return void missing.push([code, nPath, 1]);
|
||||
}
|
||||
missing.push([code, k, 1]);
|
||||
}
|
||||
});
|
||||
Object.keys(translation).forEach(function (k) {
|
||||
if (/^_/.test(k) || k === 'driveReadme') { return; }
|
||||
if (typeof Default[k] === "undefined") {
|
||||
missing.push([code, k, 0]);
|
||||
}
|
||||
if (typeof ref[k] !== typeof translated[k]) {
|
||||
return void missing.push([code, nPath, 3]);
|
||||
}
|
||||
if (typeof ref[k] === "object" && !Array.isArray(ref[k])) {
|
||||
checkInObject(ref[k], translated[k], nPath);
|
||||
}
|
||||
});
|
||||
Object.keys(translated).forEach(function (k) {
|
||||
if (/^_/.test(k) || k === 'driveReadme') { return; }
|
||||
var nPath = path.slice();
|
||||
nPath.push(k);
|
||||
if (typeof ref[k] === "undefined") {
|
||||
missing.push([code, nPath, 0]);
|
||||
}
|
||||
});
|
||||
};
|
||||
checkInObject(Default, translation, []);
|
||||
// Push the removals at the end
|
||||
missing.sort(function (a, b) {
|
||||
if (a[2] === 0 && b[2] !== 0) return 1;
|
||||
if (a[2] !== 0 && b[2] === 0) return -1;
|
||||
return 0;
|
||||
});
|
||||
Array.prototype.push.apply(allMissing, missing); // Destructive concat
|
||||
});
|
||||
cb(missing);
|
||||
cb(allMissing);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -22,8 +22,7 @@ define(function () {
|
||||
out.button_newslide = 'New Presentation';
|
||||
out.button_newwhiteboard = 'New Whiteboard';
|
||||
|
||||
// NOTE: We want to update the 'common_connectionLost' key.
|
||||
// Please do not add a new 'updated_common_connectionLostAndInfo' but change directly the value of 'common_connectionLost'
|
||||
// NOTE: Remove updated_0_ if we need an updated_1_
|
||||
out.updated_0_common_connectionLost = "<b>Server Connection Lost</b><br>You're now in read-only mode until the connection is back.";
|
||||
out.common_connectionLost = out.updated_0_common_connectionLost;
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
define([
|
||||
'jquery',
|
||||
'/common/cryptpad-common.js',
|
||||
'/common/common-util.js',
|
||||
'/customize/messages.js',
|
||||
'/customize/translations/messages.js',
|
||||
], function ($, Cryptpad, English) {
|
||||
], function ($, Util, Messages, English) {
|
||||
|
||||
var $body = $('body');
|
||||
|
||||
@ -11,38 +12,40 @@ define([
|
||||
};
|
||||
|
||||
var todo = function (missing) {
|
||||
var str = "";
|
||||
var need = 1;
|
||||
var currentLang = "";
|
||||
var currentState = 1;
|
||||
|
||||
if (missing.length) {
|
||||
$body.append(pre(missing.map(function (msg) {
|
||||
var res = "";
|
||||
var code = msg[0];
|
||||
var key = msg[1];
|
||||
var needed = msg[2];
|
||||
var lang = msg[0];
|
||||
var key = msg[1]; // Array
|
||||
var state = msg[2]; // 0 === toDelete, 1 === missing, 2 === updated, 3 === invalid (wrong type)
|
||||
var value = msg[3] || '""';
|
||||
|
||||
if (str !== code) {
|
||||
if (str !== "")
|
||||
if (currentLang !== lang) {
|
||||
if (currentLang !== "")
|
||||
{
|
||||
res += '\n';
|
||||
}
|
||||
str = code;
|
||||
res += '/*\n *\n * ' + code + '\n *\n */\n\n';
|
||||
currentLang = lang;
|
||||
res += '/*\n *\n * ' + lang + '\n *\n */\n\n';
|
||||
}
|
||||
if (need !== needed) {
|
||||
need = needed;
|
||||
if (need === 0)
|
||||
if (currentState !== state) {
|
||||
currentState = state;
|
||||
if (currentState === 0)
|
||||
{
|
||||
res += '\n// TODO: These keys are not needed anymore and should be removed ('+ code + ')\n\n';
|
||||
res += '\n// TODO: These keys are not needed anymore and should be removed ('+ lang + ')\n\n';
|
||||
}
|
||||
}
|
||||
|
||||
res += (need ? '' : '// ') + 'out.' + key + ' = ' + value + ';';
|
||||
if (need === 1) {
|
||||
res += ' // ' + JSON.stringify(English[key]);
|
||||
} else if (need === 2) {
|
||||
res += ' // TODO: Key updated --> make sure the updated key "'+ value +'" exists and is translated before that one.';
|
||||
res += (currentState ? '' : '// ') + 'out.' + key.join('.') + ' = ' + value + ';';
|
||||
if (currentState === 1) {
|
||||
res += ' // ' + JSON.stringify(Util.find(English, key));
|
||||
} else if (currentState === 2) {
|
||||
res += ' // TODO: Key updated --> make sure the updated key "'+ value +'" exists and is translated before this one.';
|
||||
} else if (currentState === 3) {
|
||||
res += ' // NOTE: this key has an invalid type! Original value: ' + JSON.stringify(Util.find(English, key));
|
||||
}
|
||||
return res;
|
||||
}).join('\n')));
|
||||
@ -50,5 +53,5 @@ define([
|
||||
$body.text('// All keys are present in all translations');
|
||||
}
|
||||
};
|
||||
Cryptpad.Messages._checkTranslationState(todo);
|
||||
Messages._checkTranslationState(todo);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user