cryptpad/customize.dist/messages.js

130 lines
4.7 KiB
JavaScript
Raw Normal View History

define(['/customize/languageSelector.js',
'/customize/translations/messages.js',
'/customize/translations/messages.es.js',
'/customize/translations/messages.fr.js',
// 1) additional translation files can be added here...
2016-12-17 00:38:53 +08:00
'/customize/translations/messages.pl.js',
'/customize/translations/messages.de.js',
'/customize/translations/messages.pt-br.js',
'/bower_components/jquery/dist/jquery.min.js'],
// 2) name your language module here...
function(LS, Default, Spanish, French, Polish, German, BrPortuguese) {
var $ = window.jQuery;
// 3) add your module to this map so it gets used
var map = {
'fr': French,
'es': Spanish,
2016-12-17 00:38:53 +08:00
'pl': Polish,
2016-11-19 08:24:23 +08:00
'de': German,
'pt-br': BrPortuguese,
};
var defaultLanguage = 'en';
var language = LS.getLanguage();
2016-07-11 23:36:53 +08:00
var messages;
2016-07-11 23:36:53 +08:00
2016-09-16 00:35:09 +08:00
if (!language || language === defaultLanguage || language === 'default' || !map[language]) {
messages = Default;
}
else {
// Add the translated keys to the returned object
messages = $.extend(true, {}, Default, map[language]);
}
2016-07-11 23:36:53 +08:00
2016-10-25 23:29:13 +08:00
// messages_languages return the available translations and their name in an object :
// { "en": "English", "fr": "French", ... }
messages._languages = {
'en': Default._languageName
2016-10-25 23:29:13 +08:00
};
for (var l in map) {
messages._languages[l] = map[l]._languageName || l;
}
messages._initSelector = LS.main;
messages._checkTranslationState = function () {
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);
}
});
2016-11-03 23:05:02 +08:00
if (typeof(translation._languageName) !== 'string') {
var warning = 'key [_languageName] is missing from translation [' + code + ']';
missing.push(warning);
}
});
return missing;
};
2016-09-16 00:35:09 +08:00
// Get keys with parameters
messages._getKey = function (key, argArray) {
if (!messages[key]) { return '?'; }
var text = messages[key];
return text.replace(/\{(\d+)\}/g, function (str, p1) {
return argArray[p1] || null;
});
};
2016-07-11 23:36:53 +08:00
var translateText = function (i, e) {
var $el = $(e);
var key = $el.data('localization');
$el.html(messages[key]);
};
var translateAppend = function (i, e) {
var $el = $(e);
var key = $el.data('localization-append');
$el.append(messages[key]);
};
var translateTitle = function (i, e) {
var $el = $(this);
var key = $el.data('localization-title');
$el.attr('title', messages[key]);
};
var translatePlaceholder = function (i, e) {
var $el = $(this);
var key = $el.data('localization-placeholder');
$el.attr('placeholder', messages[key]);
};
2016-09-16 00:35:09 +08:00
messages._applyTranslation = function () {
$('[data-localization]').each(translateText);
$('[data-localization-append]').each(translateAppend);
$('#pad-iframe').contents().find('[data-localization]').each(translateText);
$('[data-localization-title]').each(translateTitle);
$('[data-localization-placeholder]').each(translatePlaceholder);
$('#pad-iframe').contents().find('[data-localization-title]').each(translateTitle);
2016-09-16 00:35:09 +08:00
};
// Non translatable keys
messages.initialState = [
'<p>',
'This is <strong>CryptPad</strong>, the zero knowledge realtime collaborative editor.',
'<br>',
'What you type here is encrypted so only people who have the link can access it.',
'<br>',
'Even the server cannot see what you type.',
'</p>',
'<p>',
'<small>',
'<i>What you see here, what you hear here, when you leave here, let it stay here</i>',
'</small>',
'</p>',
].join('');
messages.driveReadme = '["BODY",{"class":"cke_editable cke_editable_themed cke_contents_ltr cke_show_borders","contenteditable":"true","spellcheck":"false","style":"color: rgb(51, 51, 51);"},' +
'[["H1",{},["' + messages.driveReadme_h1 + '",["BR",{},[]]]],["UL",{},[["LI",{},["' + messages.driveReadme_li1 + '",["BR",{},[]],["UL",{},[["LI",{},["' + messages.driveReadme_li1_1 + '",["BR",{},[]]]]]]]]]]],' +
'{"metadata":{"defaultTitle":"' + messages.driveReadmeTitle + '","title":"' + messages.driveReadmeTitle + '"}}]';
return messages;
});