Do not load all the translations anymore, only the needed one

pull/1/head
yflory 8 years ago
parent 434c3a220c
commit 454d1c2052

@ -76,7 +76,7 @@
<div id="align-container"> <div id="align-container">
<div id="main-container"> <div id="main-container">
<div id="data" class="hidden"> <div id="data" class="hidden">
<p class="left" data-localization="main_p1"><!-- Zero Knowledge collaborative realtime editor. Protected from the NSA. --></p> <p class="left" data-localization="main_info"><!-- Collaborate in Confidence. --></p>
</div> </div>
<div id="userForm" class="form-group hidden"> <div id="userForm" class="form-group hidden">

@ -1,50 +0,0 @@
define(['/bower_components/jquery/dist/jquery.min.js'], function() {
var $ = window.jQuery;
var out = {};
var LS_LANG = "CRYPTPAD_LANG";
var getStoredLanguage = function () {
return localStorage.getItem(LS_LANG);
};
var storeLanguage = function (l) {
localStorage.setItem(LS_LANG, l);
};
var getBrowserLanguage = function () {
return navigator.language || navigator.userLanguage;
};
var getLanguage = out.getLanguage = function () {
return getStoredLanguage() || getBrowserLanguage();
};
var main = out.main = function ($select) {
var selector = $select || $('#language-selector');
if (!selector.length) { return; }
var $button = $(selector).find('button .buttonTitle');
// Select the current language in the list
var language = getLanguage();
var option = $(selector).find('[data-value="' + language + '"]');
if ($(option).length) {
$button.text($(option).text());
}
else {
$button.text('English');
}
// Listen for language change
$(selector).find('a.languageValue').on('click', function () {
var newLanguage = $(this).attr('data-value');
storeLanguage(newLanguage);
if (newLanguage !== language) {
window.location.reload();
}
});
};
return out;
});

@ -3,9 +3,8 @@ define([
'/customize/application_config.js', '/customize/application_config.js',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/bower_components/lil-uri/uri.min.js', '/bower_components/lil-uri/uri.min.js',
'/customize/languageSelector.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
], function (Messages, Config, Cryptpad, LilUri, LS) { ], function (Messages, Config, Cryptpad, LilUri) {
var $ = window.$; var $ = window.$;
var APP = window.APP = { var APP = window.APP = {

@ -1,70 +1,76 @@
define(['/customize/languageSelector.js', (function () {
'/customize/translations/messages.js', var LS_LANG = "CRYPTPAD_LANG";
'/customize/translations/messages.es.js',
'/customize/translations/messages.fr.js', var getStoredLanguage = function () { return localStorage.getItem(LS_LANG); };
var getBrowserLanguage = function () { return navigator.language || navigator.userLanguage; };
// 1) additional translation files can be added here... var getLanguage = function () { return getStoredLanguage() || getBrowserLanguage(); };
'/customize/translations/messages.pl.js', var language = getLanguage();
'/customize/translations/messages.de.js',
'/customize/translations/messages.pt-br.js', // add your module to this map so it gets used
var map = {
'fr': 'Français',
'/bower_components/jquery/dist/jquery.min.js'], 'es': 'Español',
'pl': 'Polski',
// 2) name your language module here... 'de': 'Deutsch',
function(LS, Default, Spanish, French, Polish, German, BrPortuguese) { 'pt-br': 'Português do Brasil'
};
var req = ['/customize/translations/messages.js'];
if (language && map[language]) { req.push('/customize/translations/messages.' + language + '.js'); }
req.push('/bower_components/jquery/dist/jquery.min.js');
define(req, function(Default, Language) {
var $ = window.jQuery; var $ = window.jQuery;
// 3) add your module to this map so it gets used var externalMap = JSON.parse(JSON.stringify(map));
var map = {
'fr': French,
'es': Spanish,
'pl': Polish,
'de': German,
'pt-br': BrPortuguese,
};
map.en = 'English';
var defaultLanguage = 'en'; var defaultLanguage = 'en';
var language = LS.getLanguage();
var messages; var messages;
if (!language || language === defaultLanguage || language === 'default' || !map[language]) { if (!Language || !language || language === defaultLanguage || language === 'default' || !map[language]) {
messages = Default; messages = Default;
} }
else { else {
// Add the translated keys to the returned object // Add the translated keys to the returned object
messages = $.extend(true, {}, Default, map[language]); messages = $.extend(true, {}, Default, Language);
} }
// messages_languages return the available translations and their name in an object : messages._languages = map;
// { "en": "English", "fr": "French", ... }
messages._languages = {
'en': Default._languageName
};
for (var l in map) {
messages._languages[l] = map[l]._languageName || l;
}
messages._initSelector = LS.main; messages._checkTranslationState = function (cb) {
messages._checkTranslationState = function () { if (typeof(cb) !== "function") { return; }
var missing = []; var missing = [];
Object.keys(map).forEach(function (code) { var reqs = [];
var translation = map[code]; Object.keys(externalMap).forEach(function (code) {
Object.keys(Default).forEach(function (k) { reqs.push('/customize/translations/messages.' + code + '.js');
if (/^_/.test(k) || /nitialState$/.test(k)) { return; } });
if (!translation[k]) { require(reqs, function () {
var warning = "key [" + k + "] is missing from translation [" + code + "]"; var langs = arguments;
Object.keys(externalMap).forEach(function (code, i) {
var translation = langs[i];
Object.keys(Default).forEach(function (k) {
if (/^_/.test(k) || /nitialState$/.test(k)) { return; }
if (!translation[k]) {
var warning = "key [" + k + "] is missing from translation [" + code + "]";
missing.push(warning);
}
});
Object.keys(translation).forEach(function (k) {
if (/^_/.test(k) || /nitialState$/.test(k)) { return; }
if (!Default[k]) {
var warning = "key [" + k + "] from [" + code + "] is not needed anymore and should be removed";
missing.push(warning);
}
});
/*if (typeof(translation._languageName) !== 'string') {
var warning = 'key [_languageName] is missing from translation [' + code + ']';
missing.push(warning); missing.push(warning);
} }*/
}); });
if (typeof(translation._languageName) !== 'string') { cb(missing);
var warning = 'key [_languageName] is missing from translation [' + code + ']';
missing.push(warning);
}
}); });
return missing;
}; };
// Get keys with parameters // Get keys with parameters
@ -76,6 +82,35 @@ define(['/customize/languageSelector.js',
}); });
}; };
// Add handler to the language selector
var storeLanguage = function (l) {
localStorage.setItem(LS_LANG, l);
};
messages._initSelector = function ($select) {
var selector = $select || $('#language-selector');
if (!selector.length) { return; }
var $button = $(selector).find('button .buttonTitle');
// Select the current language in the list
var option = $(selector).find('[data-value="' + language + '"]');
if ($(option).length) {
$button.text($(option).text());
}
else {
$button.text('English');
}
// Listen for language change
$(selector).find('a.languageValue').on('click', function () {
var newLanguage = $(this).attr('data-value');
storeLanguage(newLanguage);
if (newLanguage !== language) {
window.location.reload();
}
});
};
var translateText = function (i, e) { var translateText = function (i, e) {
var $el = $(e); var $el = $(e);
var key = $el.data('localization'); var key = $el.data('localization');
@ -126,4 +161,6 @@ define(['/customize/languageSelector.js',
'{"metadata":{"defaultTitle":"' + messages.driveReadmeTitle + '","title":"' + messages.driveReadmeTitle + '"}}]'; '{"metadata":{"defaultTitle":"' + messages.driveReadmeTitle + '","title":"' + messages.driveReadmeTitle + '"}}]';
return messages; return messages;
}); });
}());

@ -5,7 +5,7 @@
<div id="align-container"> <div id="align-container">
<div id="main-container"> <div id="main-container">
<div id="data" class="hidden"> <div id="data" class="hidden">
<p class="left" data-localization="main_p1"><!-- Zero Knowledge collaborative realtime editor. Protected from the NSA. --></p> <p class="left" data-localization="main_info"><!-- Collaborate in Confidence. --></p>
</div> </div>
<div id="userForm" class="form-group hidden"> <div id="userForm" class="form-group hidden">

@ -1,10 +1,6 @@
define(function () { define(function () {
var out = {}; var out = {};
// translations must set this key for their language to be available in
// the language dropdowns that are shown throughout Cryptpad's interface
out._languageName = "Français";
out.main_title = "Cryptpad: Éditeur collaboratif en temps réel, zero knowledge"; out.main_title = "Cryptpad: Éditeur collaboratif en temps réel, zero knowledge";
out.main_slogan = "L'unité est la force, la collaboration est la clé"; out.main_slogan = "L'unité est la force, la collaboration est la clé";
@ -102,9 +98,6 @@ define(function () {
out.cancel = "Annuler"; out.cancel = "Annuler";
out.cancelButton = 'Annuler (Echap)'; out.cancelButton = 'Annuler (Echap)';
out.loginText = '<p>Votre nom d\'utilisateur et votre mot de passe sont utilisés pour générer une clé unique qui reste inconnue de notre serveur.</p>\n' +
'<p>Faites attention de ne pas oublier vos identifiants puisqu\'ils seront impossible à récupérer.</p>'; //TODO
// Polls // Polls
out.poll_title = "Sélecteur de date Zero Knowledge"; out.poll_title = "Sélecteur de date Zero Knowledge";
@ -206,9 +199,6 @@ define(function () {
out.logoutButton = "Déconnexion"; out.logoutButton = "Déconnexion";
out.settingsButton = "Préférences"; out.settingsButton = "Préférences";
out.username_label = "Nom d'utilisateur : ";
out.displayname_label = "Nom affiché : ";
out.login_username = "Nom d'utilisateur"; out.login_username = "Nom d'utilisateur";
out.login_password = "Mot de passe"; out.login_password = "Mot de passe";
out.login_confirm = "Confirmer votre mot de passe"; out.login_confirm = "Confirmer votre mot de passe";
@ -261,7 +251,7 @@ define(function () {
// index.html // index.html
out.main_p1 = "<h2>Collaborez avec confiance</h2><br>Développez vos idées en groupe avec des documents partagés; la technologie <strong>Zero Knowledge</strong> sécurise vos données."; out.main_info = "<h2>Collaborez avec confiance</h2><br>Développez vos idées en groupe avec des documents partagés; la technologie <strong>Zero Knowledge</strong> sécurise vos données.";
out.main_howitworks = 'Comment ça fonctionne'; out.main_howitworks = 'Comment ça fonctionne';
out.main_zeroKnowledge = 'Zero Knowledge'; out.main_zeroKnowledge = 'Zero Knowledge';
@ -287,8 +277,6 @@ define(function () {
out.footer_contact = "Contact"; out.footer_contact = "Contact";
out.footer_aboutUs = "À propos de nous"; out.footer_aboutUs = "À propos de nous";
out.form_title = "Tous vos pads, partout où vous allez !";
out.about = "À propos"; out.about = "À propos";
out.privacy = "Vie privée"; out.privacy = "Vie privée";
out.contact = "Contact"; out.contact = "Contact";

@ -1,11 +1,6 @@
define(function () { define(function () {
var out = {}; var out = {};
// translations must set this key for their language to be available in
// the language dropdowns that are shown throughout Cryptpad's interface
// NOTE: translate that name in your language ("Français" and not "French")
out._languageName = 'English';
out.main_title = "Cryptpad: Zero Knowledge, Collaborative Real Time Editing"; out.main_title = "Cryptpad: Zero Knowledge, Collaborative Real Time Editing";
out.main_slogan = "Unity is Strength - Collaboration is Key"; // TODO remove? out.main_slogan = "Unity is Strength - Collaboration is Key"; // TODO remove?
@ -259,7 +254,7 @@ define(function () {
// index.html // index.html
out.main_p1 = "<h1>Collaborate in Confidence</h1><br> Grow your ideas together with shared documents while <strong>Zero Knowledge</strong> technology secures your privacy; even from us."; out.main_info = "<h1>Collaborate in Confidence</h1><br> Grow your ideas together with shared documents while <strong>Zero Knowledge</strong> technology secures your privacy; even from us.";
out.main_howitworks = 'How It Works'; out.main_howitworks = 'How It Works';
out.main_zeroKnowledge = 'Zero Knowledge'; out.main_zeroKnowledge = 'Zero Knowledge';

@ -142,16 +142,18 @@ define([
}); });
assert(function () { assert(function () {
var missing = Cryptpad.Messages._checkTranslationState(); var todo = function (missing) {
if (missing.length !== 0) {
missing.forEach(function (msg) {
console.log('* ' + msg);
});
if (missing.length !== 0) { // No, this is crappy, it's going to cause tests to fail basically all of the time.
missing.forEach(function (msg) { //return false;
console.log('* ' + msg); }
}); };
Cryptpad.Messages._checkTranslationState(todo);
// No, this is crappy, it's going to cause tests to fail basically all of the time.
//return false;
}
return true; return true;
}, "expected all translation keys in default language to be present in all translations. See console for details."); }, "expected all translation keys in default language to be present in all translations. See console for details.");

@ -5,17 +5,19 @@ define([
var $ = window.jQuery; var $ = window.jQuery;
var $body = $('body'); var $body = $('body');
var missing = Cryptpad.Messages._checkTranslationState();
var pre = function (text, opt) { var pre = function (text, opt) {
return $('<pre>', opt).text(text); return $('<pre>', opt).text(text);
}; };
if (missing.length) { var todo = function (missing) {
$body.append(pre(missing.map(function (msg) { if (missing.length) {
return '* ' + msg; $body.append(pre(missing.map(function (msg) {
}).join('\n'))); return '* ' + msg;
} else { }).join('\n')));
$body.text('All keys are present in all translations'); } else {
} $body.text('All keys are present in all translations');
}
};
Cryptpad.Messages._checkTranslationState(todo);
}); });

@ -1,9 +1,8 @@
define([ define([
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/customize/languageSelector.js',
'/common/login.js', '/common/login.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
], function (Cryptpad, LS, Login) { ], function (Cryptpad, Login) {
var $ = window.$; var $ = window.$;
var APP = window.APP = { var APP = window.APP = {

@ -18,6 +18,7 @@
<script> <script>
require.config({ require.config({
waitSeconds: 60, waitSeconds: 60,
urlArgs: "bust=1.0.0",
}); });
</script> </script>
</head> </head>

Loading…
Cancel
Save