2017-02-21 01:29:06 +08:00
|
|
|
(function () {
|
|
|
|
var LS_LANG = "CRYPTPAD_LANG";
|
|
|
|
|
|
|
|
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'
|
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
2016-09-15 00:08:52 +08:00
|
|
|
var $ = window.jQuery;
|
2014-11-03 23:07:39 +08:00
|
|
|
|
2017-02-21 01:29:06 +08:00
|
|
|
var externalMap = JSON.parse(JSON.stringify(map));
|
2014-11-03 23:07:39 +08:00
|
|
|
|
2017-02-21 01:29:06 +08:00
|
|
|
map.en = 'English';
|
2016-09-15 00:08:52 +08:00
|
|
|
var defaultLanguage = 'en';
|
2014-11-03 23:07:39 +08:00
|
|
|
|
2016-09-15 00:08:52 +08:00
|
|
|
var messages;
|
2016-07-11 23:36:53 +08:00
|
|
|
|
2017-02-21 01:29:06 +08:00
|
|
|
if (!Language || !language || language === defaultLanguage || language === 'default' || !map[language]) {
|
2016-09-16 00:35:09 +08:00
|
|
|
messages = Default;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Add the translated keys to the returned object
|
2017-02-21 01:29:06 +08:00
|
|
|
messages = $.extend(true, {}, Default, Language);
|
2016-09-16 00:35:09 +08:00
|
|
|
}
|
2016-07-11 23:36:53 +08:00
|
|
|
|
2017-02-21 01:29:06 +08:00
|
|
|
messages._languages = map;
|
2016-10-25 21:22:35 +08:00
|
|
|
|
2017-02-21 01:29:06 +08:00
|
|
|
messages._checkTranslationState = function (cb) {
|
|
|
|
if (typeof(cb) !== "function") { return; }
|
2016-10-24 17:41:36 +08:00
|
|
|
var missing = [];
|
2017-02-21 01:29:06 +08:00
|
|
|
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]) {
|
2017-02-21 17:53:30 +08:00
|
|
|
//var warning = "key [" + k + "] is missing from translation [" + code + "]";
|
|
|
|
//missing.push(warning);
|
|
|
|
missing.push([code, k, 1]);
|
2017-02-21 01:29:06 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Object.keys(translation).forEach(function (k) {
|
|
|
|
if (/^_/.test(k) || /nitialState$/.test(k)) { return; }
|
|
|
|
if (!Default[k]) {
|
2017-02-21 17:53:30 +08:00
|
|
|
//var warning = "key [" + k + "] from [" + code + "] is not needed anymore and should be removed";
|
|
|
|
//missing.push(warning);
|
|
|
|
missing.push([code, k, 0]);
|
2017-02-21 01:29:06 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
/*if (typeof(translation._languageName) !== 'string') {
|
|
|
|
var warning = 'key [_languageName] is missing from translation [' + code + ']';
|
2016-10-24 17:41:36 +08:00
|
|
|
missing.push(warning);
|
2017-02-21 01:29:06 +08:00
|
|
|
}*/
|
2016-10-24 17:41:36 +08:00
|
|
|
});
|
2017-02-21 01:29:06 +08:00
|
|
|
cb(missing);
|
2016-10-24 17:41:36 +08:00
|
|
|
});
|
|
|
|
};
|
2016-10-25 21:22:35 +08:00
|
|
|
|
2016-09-16 00:35:09 +08:00
|
|
|
// Get keys with parameters
|
2016-09-15 00:08:52 +08:00
|
|
|
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
|
|
|
|
2017-02-21 01:29:06 +08:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-11-17 00:11:48 +08:00
|
|
|
var translateText = function (i, e) {
|
|
|
|
var $el = $(e);
|
|
|
|
var key = $el.data('localization');
|
|
|
|
$el.html(messages[key]);
|
|
|
|
};
|
2017-01-21 01:21:51 +08:00
|
|
|
var translateAppend = function (i, e) {
|
|
|
|
var $el = $(e);
|
|
|
|
var key = $el.data('localization-append');
|
|
|
|
$el.append(messages[key]);
|
|
|
|
};
|
2016-11-17 00:11:48 +08:00
|
|
|
var translateTitle = function (i, e) {
|
|
|
|
var $el = $(this);
|
|
|
|
var key = $el.data('localization-title');
|
|
|
|
$el.attr('title', messages[key]);
|
|
|
|
};
|
2016-12-16 22:20:01 +08:00
|
|
|
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 () {
|
2016-11-17 00:11:48 +08:00
|
|
|
$('[data-localization]').each(translateText);
|
2017-01-21 01:21:51 +08:00
|
|
|
$('[data-localization-append]').each(translateAppend);
|
2016-11-17 00:11:48 +08:00
|
|
|
$('#pad-iframe').contents().find('[data-localization]').each(translateText);
|
|
|
|
$('[data-localization-title]').each(translateTitle);
|
2017-01-06 20:52:30 +08:00
|
|
|
$('[data-localization-placeholder]').each(translatePlaceholder);
|
2016-11-17 00:11:48 +08:00
|
|
|
$('#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('');
|
|
|
|
|
2017-02-17 00:22:45 +08:00
|
|
|
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 + '"}}]';
|
|
|
|
|
2016-09-15 00:08:52 +08:00
|
|
|
return messages;
|
2017-02-21 01:29:06 +08:00
|
|
|
|
2014-11-03 23:07:39 +08:00
|
|
|
});
|
2017-02-21 01:29:06 +08:00
|
|
|
}());
|