Do not load all the translations anymore, only the needed one
This commit is contained in:
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,57 +1,55 @@
|
|||||||
define(['/customize/languageSelector.js',
|
(function () {
|
||||||
'/customize/translations/messages.js',
|
var LS_LANG = "CRYPTPAD_LANG";
|
||||||
'/customize/translations/messages.es.js',
|
|
||||||
'/customize/translations/messages.fr.js',
|
|
||||||
|
|
||||||
// 1) additional translation files can be added here...
|
var getStoredLanguage = function () { return localStorage.getItem(LS_LANG); };
|
||||||
'/customize/translations/messages.pl.js',
|
var getBrowserLanguage = function () { return navigator.language || navigator.userLanguage; };
|
||||||
'/customize/translations/messages.de.js',
|
var getLanguage = function () { return getStoredLanguage() || getBrowserLanguage(); };
|
||||||
'/customize/translations/messages.pt-br.js',
|
var language = getLanguage();
|
||||||
|
|
||||||
|
// add your module to this map so it gets used
|
||||||
|
var map = {
|
||||||
|
'fr': 'Français',
|
||||||
|
'es': 'Español',
|
||||||
|
'pl': 'Polski',
|
||||||
|
'de': 'Deutsch',
|
||||||
|
'pt-br': 'Português do Brasil'
|
||||||
|
};
|
||||||
|
|
||||||
'/bower_components/jquery/dist/jquery.min.js'],
|
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');
|
||||||
|
|
||||||
// 2) name your language module here...
|
define(req, function(Default, Language) {
|
||||||
function(LS, Default, Spanish, French, Polish, German, BrPortuguese) {
|
|
||||||
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) {
|
||||||
|
reqs.push('/customize/translations/messages.' + code + '.js');
|
||||||
|
});
|
||||||
|
require(reqs, function () {
|
||||||
|
var langs = arguments;
|
||||||
|
Object.keys(externalMap).forEach(function (code, i) {
|
||||||
|
var translation = langs[i];
|
||||||
Object.keys(Default).forEach(function (k) {
|
Object.keys(Default).forEach(function (k) {
|
||||||
if (/^_/.test(k) || /nitialState$/.test(k)) { return; }
|
if (/^_/.test(k) || /nitialState$/.test(k)) { return; }
|
||||||
if (!translation[k]) {
|
if (!translation[k]) {
|
||||||
@ -59,12 +57,20 @@ define(['/customize/languageSelector.js',
|
|||||||
missing.push(warning);
|
missing.push(warning);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (typeof(translation._languageName) !== 'string') {
|
Object.keys(translation).forEach(function (k) {
|
||||||
var warning = 'key [_languageName] is missing from translation [' + code + ']';
|
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);
|
missing.push(warning);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return missing;
|
/*if (typeof(translation._languageName) !== 'string') {
|
||||||
|
var warning = 'key [_languageName] is missing from translation [' + code + ']';
|
||||||
|
missing.push(warning);
|
||||||
|
}*/
|
||||||
|
});
|
||||||
|
cb(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,8 +142,7 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert(function () {
|
assert(function () {
|
||||||
var missing = Cryptpad.Messages._checkTranslationState();
|
var todo = function (missing) {
|
||||||
|
|
||||||
if (missing.length !== 0) {
|
if (missing.length !== 0) {
|
||||||
missing.forEach(function (msg) {
|
missing.forEach(function (msg) {
|
||||||
console.log('* ' + msg);
|
console.log('* ' + msg);
|
||||||
@ -152,6 +151,9 @@ define([
|
|||||||
// No, this is crappy, it's going to cause tests to fail basically all of the time.
|
// No, this is crappy, it's going to cause tests to fail basically all of the time.
|
||||||
//return false;
|
//return false;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
Cryptpad.Messages._checkTranslationState(todo);
|
||||||
|
|
||||||
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,12 +5,12 @@ 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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var todo = function (missing) {
|
||||||
if (missing.length) {
|
if (missing.length) {
|
||||||
$body.append(pre(missing.map(function (msg) {
|
$body.append(pre(missing.map(function (msg) {
|
||||||
return '* ' + msg;
|
return '* ' + msg;
|
||||||
@ -18,4 +18,6 @@ define([
|
|||||||
} else {
|
} else {
|
||||||
$body.text('All keys are present in all translations');
|
$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…
x
Reference in New Issue
Block a user