Do not load all the translations anymore, only the needed one
parent
434c3a220c
commit
454d1c2052
|
@ -76,7 +76,7 @@
|
|||
<div id="align-container">
|
||||
<div id="main-container">
|
||||
<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 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',
|
||||
'/common/cryptpad-common.js',
|
||||
'/bower_components/lil-uri/uri.min.js',
|
||||
'/customize/languageSelector.js',
|
||||
'/bower_components/jquery/dist/jquery.min.js',
|
||||
], function (Messages, Config, Cryptpad, LilUri, LS) {
|
||||
], function (Messages, Config, Cryptpad, LilUri) {
|
||||
var $ = window.$;
|
||||
|
||||
var APP = window.APP = {
|
||||
|
|
|
@ -1,70 +1,76 @@
|
|||
define(['/customize/languageSelector.js',
|
||||
'/customize/translations/messages.js',
|
||||
'/customize/translations/messages.es.js',
|
||||
'/customize/translations/messages.fr.js',
|
||||
(function () {
|
||||
var LS_LANG = "CRYPTPAD_LANG";
|
||||
|
||||
// 1) additional translation files can be added here...
|
||||
'/customize/translations/messages.pl.js',
|
||||
'/customize/translations/messages.de.js',
|
||||
'/customize/translations/messages.pt-br.js',
|
||||
var getStoredLanguage = function () { return localStorage.getItem(LS_LANG); };
|
||||
var getBrowserLanguage = function () { return navigator.language || navigator.userLanguage; };
|
||||
var getLanguage = function () { return getStoredLanguage() || getBrowserLanguage(); };
|
||||
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...
|
||||
function(LS, Default, Spanish, French, Polish, German, BrPortuguese) {
|
||||
define(req, function(Default, Language) {
|
||||
var $ = window.jQuery;
|
||||
|
||||
// 3) add your module to this map so it gets used
|
||||
var map = {
|
||||
'fr': French,
|
||||
'es': Spanish,
|
||||
'pl': Polish,
|
||||
'de': German,
|
||||
'pt-br': BrPortuguese,
|
||||
};
|
||||
var externalMap = JSON.parse(JSON.stringify(map));
|
||||
|
||||
map.en = 'English';
|
||||
var defaultLanguage = 'en';
|
||||
|
||||
var language = LS.getLanguage();
|
||||
|
||||
var messages;
|
||||
|
||||
if (!language || language === defaultLanguage || language === 'default' || !map[language]) {
|
||||
if (!Language || !language || language === defaultLanguage || language === 'default' || !map[language]) {
|
||||
messages = Default;
|
||||
}
|
||||
else {
|
||||
// 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 :
|
||||
// { "en": "English", "fr": "French", ... }
|
||||
messages._languages = {
|
||||
'en': Default._languageName
|
||||
};
|
||||
for (var l in map) {
|
||||
messages._languages[l] = map[l]._languageName || l;
|
||||
}
|
||||
messages._languages = map;
|
||||
|
||||
messages._initSelector = LS.main;
|
||||
messages._checkTranslationState = function () {
|
||||
messages._checkTranslationState = function (cb) {
|
||||
if (typeof(cb) !== "function") { return; }
|
||||
var missing = [];
|
||||
Object.keys(map).forEach(function (code) {
|
||||
var translation = map[code];
|
||||
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);
|
||||
}
|
||||
});
|
||||
if (typeof(translation._languageName) !== 'string') {
|
||||
var warning = 'key [_languageName] is missing from translation [' + code + ']';
|
||||
missing.push(warning);
|
||||
}
|
||||
var reqs = [];
|
||||
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) {
|
||||
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);
|
||||
}*/
|
||||
});
|
||||
cb(missing);
|
||||
});
|
||||
return missing;
|
||||
};
|
||||
|
||||
// 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 $el = $(e);
|
||||
var key = $el.data('localization');
|
||||
|
@ -126,4 +161,6 @@ define(['/customize/languageSelector.js',
|
|||
'{"metadata":{"defaultTitle":"' + messages.driveReadmeTitle + '","title":"' + messages.driveReadmeTitle + '"}}]';
|
||||
|
||||
return messages;
|
||||
|
||||
});
|
||||
}());
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<div id="align-container">
|
||||
<div id="main-container">
|
||||
<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 id="userForm" class="form-group hidden">
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
define(function () {
|
||||
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_slogan = "L'unité est la force, la collaboration est la clé";
|
||||
|
||||
|
@ -102,9 +98,6 @@ define(function () {
|
|||
out.cancel = "Annuler";
|
||||
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
|
||||
|
||||
out.poll_title = "Sélecteur de date Zero Knowledge";
|
||||
|
@ -206,9 +199,6 @@ define(function () {
|
|||
out.logoutButton = "Déconnexion";
|
||||
out.settingsButton = "Préférences";
|
||||
|
||||
out.username_label = "Nom d'utilisateur : ";
|
||||
out.displayname_label = "Nom affiché : ";
|
||||
|
||||
out.login_username = "Nom d'utilisateur";
|
||||
out.login_password = "Mot de passe";
|
||||
out.login_confirm = "Confirmer votre mot de passe";
|
||||
|
@ -261,7 +251,7 @@ define(function () {
|
|||
|
||||
// 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_zeroKnowledge = 'Zero Knowledge';
|
||||
|
@ -287,8 +277,6 @@ define(function () {
|
|||
out.footer_contact = "Contact";
|
||||
out.footer_aboutUs = "À propos de nous";
|
||||
|
||||
out.form_title = "Tous vos pads, partout où vous allez !";
|
||||
|
||||
out.about = "À propos";
|
||||
out.privacy = "Vie privée";
|
||||
out.contact = "Contact";
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
define(function () {
|
||||
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_slogan = "Unity is Strength - Collaboration is Key"; // TODO remove?
|
||||
|
||||
|
@ -259,7 +254,7 @@ define(function () {
|
|||
|
||||
// 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_zeroKnowledge = 'Zero Knowledge';
|
||||
|
|
|
@ -142,16 +142,18 @@ define([
|
|||
});
|
||||
|
||||
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) {
|
||||
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);
|
||||
|
||||
// No, this is crappy, it's going to cause tests to fail basically all of the time.
|
||||
//return false;
|
||||
}
|
||||
return true;
|
||||
}, "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 $body = $('body');
|
||||
var missing = Cryptpad.Messages._checkTranslationState();
|
||||
|
||||
var pre = function (text, opt) {
|
||||
return $('<pre>', opt).text(text);
|
||||
};
|
||||
|
||||
if (missing.length) {
|
||||
$body.append(pre(missing.map(function (msg) {
|
||||
return '* ' + msg;
|
||||
}).join('\n')));
|
||||
} else {
|
||||
$body.text('All keys are present in all translations');
|
||||
}
|
||||
var todo = function (missing) {
|
||||
if (missing.length) {
|
||||
$body.append(pre(missing.map(function (msg) {
|
||||
return '* ' + msg;
|
||||
}).join('\n')));
|
||||
} else {
|
||||
$body.text('All keys are present in all translations');
|
||||
}
|
||||
};
|
||||
Cryptpad.Messages._checkTranslationState(todo);
|
||||
});
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
define([
|
||||
'/common/cryptpad-common.js',
|
||||
'/customize/languageSelector.js',
|
||||
'/common/login.js',
|
||||
'/bower_components/jquery/dist/jquery.min.js',
|
||||
], function (Cryptpad, LS, Login) {
|
||||
], function (Cryptpad, Login) {
|
||||
var $ = window.$;
|
||||
|
||||
var APP = window.APP = {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
<script>
|
||||
require.config({
|
||||
waitSeconds: 60,
|
||||
urlArgs: "bust=1.0.0",
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
|
Loading…
Reference in New Issue