From 2d30393243740de3459806f6b20a65b9e84ae2db Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 23 Feb 2017 11:45:00 +0100 Subject: [PATCH] Add support for updated translation key --- customize.dist/messages.js | 23 +++++++++++++++++----- customize.dist/translations/messages.es.js | 3 ++- customize.dist/translations/messages.fr.js | 3 ++- customize.dist/translations/messages.js | 4 ++-- www/assert/main.js | 16 --------------- www/assert/translations/main.js | 8 +++++--- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/customize.dist/messages.js b/customize.dist/messages.js index fb613d591..629a87054 100644 --- a/customize.dist/messages.js +++ b/customize.dist/messages.js @@ -50,9 +50,26 @@ define(req, function(Default, Language) { var langs = arguments; Object.keys(externalMap).forEach(function (code, i) { 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; } + } + updated[key] = k; + } + }); Object.keys(Default).forEach(function (k) { if (/^_/.test(k)) { return; } - if (!translation[k]) { + if (!translation[k] || updated[k]) { + if (updated[k]) { + missing.push([code, k, 2, 'out.' + updated[k]]); + return; + } missing.push([code, k, 1]); } }); @@ -62,10 +79,6 @@ define(req, function(Default, Language) { missing.push([code, k, 0]); } }); - /*if (typeof(translation._languageName) !== 'string') { - var warning = 'key [_languageName] is missing from translation [' + code + ']'; - missing.push(warning); - }*/ }); cb(missing); }); diff --git a/customize.dist/translations/messages.es.js b/customize.dist/translations/messages.es.js index d9f6a8544..c24e1df7c 100644 --- a/customize.dist/translations/messages.es.js +++ b/customize.dist/translations/messages.es.js @@ -12,7 +12,8 @@ define(function () { out.type.poll = 'Encuesta'; out.type.slide = 'Presentación'; - out.common_connectionLost = "Connexión perdida
El documento está ahora en modo solo lectura hasta que la conexión vuelva."; + out.updated_0_common_connectionLost = "Connexión perdida
El documento está ahora en modo solo lectura hasta que la conexión vuelva."; + out.common_connectionLost = out.updated_0_common_connectionLost; out.disconnected = "Desconectado"; out.synchronizing = "Sincronización"; diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 1ad5e907d..b96d497d3 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -16,7 +16,8 @@ define(function () { out.button_newpoll = 'Nouveau sondage'; out.button_newslide = 'Nouvelle présentation'; - out.common_connectionLost = "Connexion au serveur perdue
Vous êtes désormais en mode lecture seule jusqu'au retour de la connexion."; + out.updated_0_common_connectionLost = "Connexion au serveur perdue
Vous êtes désormais en mode lecture seule jusqu'au retour de la connexion."; + out.common_connectionLost = out.updated_0_common_connectionLost; out.websocketError = 'Impossible de se connecter au serveur WebSocket...'; out.typeError = "Ce document temps-réel n'est pas compatible avec l'application sélectionnée"; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 30b051634..abfec9239 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -18,8 +18,8 @@ define(function () { // 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' - out.updated_common_connectionLostAndInfo = "Server Connection Lost
You're now in read-only mode until the connection is back."; - out.common_connectionLost = out.updated_common_connectionLostAndInfo; + out.updated_0_common_connectionLost = "Server Connection Lost
You're now in read-only mode until the connection is back."; + out.common_connectionLost = out.updated_0_common_connectionLost; out.websocketError = 'Unable to connect to the websocket server...'; out.typeError = "That realtime document is not compatible with the selected application"; diff --git a/www/assert/main.js b/www/assert/main.js index 51bdf00a8..b6a1fbd45 100644 --- a/www/assert/main.js +++ b/www/assert/main.js @@ -141,22 +141,6 @@ define([ strungJSON(orig); }); - assert(function () { - var todo = function (missing) { - if (missing.length !== 0) { - missing.forEach(function (msg) { - console.log('* ' + msg); - }); - - // No, this is crappy, it's going to cause tests to fail basically all of the time. - //return false; - } - }; - Cryptpad.Messages._checkTranslationState(todo); - - return true; - }, "expected all translation keys in default language to be present in all translations. See console for details."); - var swap = function (str, dict) { return str.replace(/\{\{(.*?)\}\}/g, function (all, key) { return typeof dict[key] !== 'undefined'? dict[key] : all; diff --git a/www/assert/translations/main.js b/www/assert/translations/main.js index 1b1683afe..e8825d422 100644 --- a/www/assert/translations/main.js +++ b/www/assert/translations/main.js @@ -21,6 +21,7 @@ define([ var code = msg[0]; var key = msg[1]; var needed = msg[2]; + var value = msg[3] || '""'; if (str !== code) { if (str !== "") @@ -38,10 +39,11 @@ define([ } } - res += (need ? '' : '// ') + 'out.' + key + ' = "";'; - if (need) - { + 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.'; } return res; }).join('\n')));