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