2017-02-21 01:29:06 +08:00
|
|
|
(function () {
|
|
|
|
// add your module to this map so it gets used
|
|
|
|
var map = {
|
2019-06-03 17:31:12 +08:00
|
|
|
'ca': 'Català',
|
2019-03-13 22:48:36 +08:00
|
|
|
'de': 'Deutsch',
|
|
|
|
'el': 'Ελληνικά',
|
2019-06-20 16:57:56 +08:00
|
|
|
'es': 'Español',
|
2020-09-17 02:08:23 +08:00
|
|
|
'fi': 'Suomi',
|
2019-03-13 22:48:36 +08:00
|
|
|
'fr': 'Français',
|
2020-03-26 18:10:44 +08:00
|
|
|
//'hi': 'हिन्दी',
|
2019-04-26 21:22:29 +08:00
|
|
|
'it': 'Italiano',
|
2019-04-17 17:14:18 +08:00
|
|
|
'nb': 'Norwegian Bokmål',
|
2019-09-23 21:15:53 +08:00
|
|
|
//'pl': 'Polski',
|
2017-05-16 20:32:54 +08:00
|
|
|
'pt-br': 'Português do Brasil',
|
|
|
|
'ro': 'Română',
|
2019-03-13 22:48:36 +08:00
|
|
|
'ru': 'Русский',
|
2020-03-21 21:57:49 +08:00
|
|
|
//'sv': 'Svenska',
|
2019-06-20 16:57:56 +08:00
|
|
|
//'te': 'తెలుగు',
|
2017-06-05 15:10:13 +08:00
|
|
|
'zh': '繁體中文',
|
2019-11-12 18:36:35 +08:00
|
|
|
//'nl': 'Nederlands'
|
2017-02-21 01:29:06 +08:00
|
|
|
};
|
|
|
|
|
2017-11-09 21:23:40 +08:00
|
|
|
var messages = {};
|
|
|
|
var LS_LANG = "CRYPTPAD_LANG";
|
2017-12-01 21:49:21 +08:00
|
|
|
var getStoredLanguage = function () { return localStorage && localStorage.getItem(LS_LANG); };
|
2017-11-09 21:23:40 +08:00
|
|
|
var getBrowserLanguage = function () { return navigator.language || navigator.userLanguage || ''; };
|
|
|
|
var getLanguage = messages._getLanguage = function () {
|
2017-09-18 20:26:54 +08:00
|
|
|
if (window.cryptpadLanguage) { return window.cryptpadLanguage; }
|
2017-03-11 00:03:30 +08:00
|
|
|
if (getStoredLanguage()) { return getStoredLanguage(); }
|
2017-11-09 21:23:40 +08:00
|
|
|
var l = getBrowserLanguage();
|
2017-03-11 00:03:30 +08:00
|
|
|
// Edge returns 'fr-FR' --> transform it to 'fr' and check again
|
2017-11-09 21:23:40 +08:00
|
|
|
return map[l] ? l :
|
2019-08-23 22:19:45 +08:00
|
|
|
(map[l.split('-')[0]] ? l.split('-')[0] :
|
|
|
|
(map[l.split('_')[0]] ? l.split('_')[0] : 'en'));
|
2017-03-11 00:03:30 +08:00
|
|
|
};
|
|
|
|
var language = getLanguage();
|
|
|
|
|
2019-01-30 21:38:21 +08:00
|
|
|
// Translations files were migrated from requirejs modules to json.
|
|
|
|
// To avoid asking every administrator to update their customized translation files,
|
|
|
|
// we use a requirejs map to redirect the old path to the new one and to use the
|
|
|
|
// requirejs json plugin
|
|
|
|
var reqPaths = {
|
|
|
|
"/common/translations/messages.js":"json!/common/translations/messages.json"
|
|
|
|
};
|
|
|
|
Object.keys(map).forEach(function (k) {
|
|
|
|
reqPaths["/common/translations/messages."+k+".js"] = "json!/common/translations/messages."+k+".json";
|
|
|
|
});
|
|
|
|
require.config({
|
|
|
|
map: {
|
|
|
|
"*": reqPaths
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-04-17 20:54:01 +08:00
|
|
|
var req = [
|
|
|
|
'/customize/application_config.js',
|
|
|
|
'/customize/translations/messages.js'
|
|
|
|
];
|
2017-02-21 01:29:06 +08:00
|
|
|
if (language && map[language]) { req.push('/customize/translations/messages.' + language + '.js'); }
|
|
|
|
|
2020-10-14 21:20:56 +08:00
|
|
|
define(req, function(AppConfig, Default, Language) {
|
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
|
|
|
|
2019-04-17 20:54:01 +08:00
|
|
|
if (AppConfig.availableLanguages) {
|
|
|
|
if (AppConfig.availableLanguages.indexOf(language) === -1) {
|
|
|
|
language = defaultLanguage;
|
|
|
|
Language = Default;
|
|
|
|
localStorage.setItem(LS_LANG, language);
|
|
|
|
}
|
|
|
|
Object.keys(map).forEach(function (l) {
|
|
|
|
if (l === defaultLanguage) { return; }
|
|
|
|
if (AppConfig.availableLanguages.indexOf(l) === -1) {
|
|
|
|
delete map[l];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-28 20:28:51 +08:00
|
|
|
var extend = function (a, b) {
|
|
|
|
for (var k in b) {
|
|
|
|
if (Array.isArray(b[k])) {
|
|
|
|
a[k] = b[k].slice();
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-14 21:20:56 +08:00
|
|
|
if (b[k] && typeof(b[k]) === "object") {
|
|
|
|
a[k] = (a[k] && typeof(a[k]) === "object" && !Array.isArray(a[k])) ? a[k] : {};
|
|
|
|
extend(a[k], b[k]);
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-28 20:28:51 +08:00
|
|
|
a[k] = b[k] || a[k];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
extend(messages, Default);
|
2017-12-01 21:49:21 +08:00
|
|
|
if (Language && language !== defaultLanguage) {
|
2016-09-16 00:35:09 +08:00
|
|
|
// Add the translated keys to the returned object
|
2019-05-28 20:28:51 +08:00
|
|
|
extend(messages, 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;
|
2017-07-10 16:59:32 +08:00
|
|
|
messages._languageUsed = language;
|
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; }
|
2018-02-07 20:08:03 +08:00
|
|
|
var allMissing = [];
|
2017-02-21 01:29:06 +08:00
|
|
|
var reqs = [];
|
2017-11-09 21:23:40 +08:00
|
|
|
Object.keys(map).forEach(function (code) {
|
2017-11-20 21:23:56 +08:00
|
|
|
if (code === defaultLanguage) { return; }
|
2017-02-21 01:29:06 +08:00
|
|
|
reqs.push('/customize/translations/messages.' + code + '.js');
|
|
|
|
});
|
|
|
|
require(reqs, function () {
|
|
|
|
var langs = arguments;
|
2017-11-09 21:23:40 +08:00
|
|
|
Object.keys(map).forEach(function (code, i) {
|
2017-11-20 21:23:56 +08:00
|
|
|
if (code === defaultLanguage) { return; }
|
2017-02-21 01:29:06 +08:00
|
|
|
var translation = langs[i];
|
2018-02-07 20:08:03 +08:00
|
|
|
var missing = [];
|
|
|
|
var checkInObject = function (ref, translated, path) {
|
|
|
|
var updated = {};
|
|
|
|
Object.keys(ref).forEach(function (k) {
|
|
|
|
if (/^updated_[0-9]+_/.test(k) && !translated[k]) {
|
|
|
|
var key = k.split('_').slice(2).join('_');
|
|
|
|
// Make sure we don't already have an update for that key. It should not happen
|
|
|
|
// but if it does, keep the latest version
|
|
|
|
if (updated[key]) {
|
|
|
|
var ek = updated[key];
|
|
|
|
if (parseInt(ek.split('_')[1]) > parseInt(k.split('_')[1])) { return; }
|
|
|
|
}
|
|
|
|
updated[key] = k;
|
2017-02-23 18:45:00 +08:00
|
|
|
}
|
2018-02-07 20:08:03 +08:00
|
|
|
});
|
|
|
|
Object.keys(ref).forEach(function (k) {
|
|
|
|
if (/^_/.test(k) || k === 'driveReadme') { return; }
|
|
|
|
var nPath = path.slice();
|
|
|
|
nPath.push(k);
|
|
|
|
if (!translated[k] || updated[k]) {
|
|
|
|
if (updated[k]) {
|
|
|
|
var uPath = path.slice();
|
|
|
|
uPath.unshift('out');
|
|
|
|
missing.push([code, nPath, 2, uPath.join('.') + '.' + updated[k]]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return void missing.push([code, nPath, 1]);
|
2017-02-23 18:45:00 +08:00
|
|
|
}
|
2018-02-07 20:08:03 +08:00
|
|
|
if (typeof ref[k] !== typeof translated[k]) {
|
|
|
|
return void missing.push([code, nPath, 3]);
|
|
|
|
}
|
|
|
|
if (typeof ref[k] === "object" && !Array.isArray(ref[k])) {
|
|
|
|
checkInObject(ref[k], translated[k], nPath);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Object.keys(translated).forEach(function (k) {
|
|
|
|
if (/^_/.test(k) || k === 'driveReadme') { return; }
|
|
|
|
var nPath = path.slice();
|
|
|
|
nPath.push(k);
|
|
|
|
if (typeof ref[k] === "undefined") {
|
|
|
|
missing.push([code, nPath, 0]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
checkInObject(Default, translation, []);
|
|
|
|
// Push the removals at the end
|
|
|
|
missing.sort(function (a, b) {
|
2018-02-08 19:24:19 +08:00
|
|
|
if (a[2] === 0 && b[2] !== 0) { return 1; }
|
|
|
|
if (a[2] !== 0 && b[2] === 0) { return -1; }
|
2018-02-07 20:08:03 +08:00
|
|
|
return 0;
|
2017-02-21 01:29:06 +08:00
|
|
|
});
|
2018-02-07 20:08:03 +08:00
|
|
|
Array.prototype.push.apply(allMissing, missing); // Destructive concat
|
2016-10-24 17:41:36 +08:00
|
|
|
});
|
2018-02-07 20:08:03 +08:00
|
|
|
cb(allMissing);
|
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];
|
2017-02-21 19:29:47 +08:00
|
|
|
if (typeof(text) === 'string') {
|
|
|
|
return text.replace(/\{(\d+)\}/g, function (str, p1) {
|
2018-01-02 19:13:43 +08:00
|
|
|
if (typeof(argArray[p1]) === 'string' || typeof(argArray[p1]) === "number") {
|
|
|
|
return argArray[p1];
|
|
|
|
}
|
|
|
|
console.error("Only strings and numbers can be used in _getKey params!");
|
|
|
|
return '';
|
2017-02-21 19:29:47 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return text;
|
|
|
|
}
|
2016-09-15 00:08:52 +08:00
|
|
|
};
|
2016-07-11 23:36:53 +08:00
|
|
|
|
2017-02-28 00:23:28 +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.readme_welcome+'"]],["P",{},["'+messages.readme_p1+'"]],["P",{},["'+messages.readme_p2+'"]],["HR",{},[]],["H2",{},["'+messages.readme_cat1+'",["BR",{},[]]]],["UL",{},[["LI",{},["'+messages._getKey("readme_cat1_l1", ['",["STRONG",{},["'+messages.newButton+'"]],"', '",["STRONG",{},["'+messages.type.pad+'"]],"'])+'"]],["LI",{},["'+messages.readme_cat1_l2+'"]],["LI",{},["'+messages._getKey("readme_cat1_l3", ['",["STRONG",{},["'+messages.fm_unsortedName+'"]],"'])+'",["UL",{},[["LI",{},["'+messages._getKey("readme_cat1_l3_l1", ['",["STRONG",{},["'+messages.fm_rootName+'"]],"'])+'"]],["LI",{},["'+messages.readme_cat1_l3_l2+'"]]]]]],["LI",{},["'+messages._getKey("readme_cat1_l4", ['",["STRONG",{},["'+messages.fm_trashName+'"]],"'])+'",["BR",{},[]]]]]],["P",{},[["BR",{},[]]]],["H2",{},["'+messages.readme_cat2+'",["BR",{},[]]]],["UL",{},[["LI",{},["'+messages._getKey("readme_cat2_l1", ['",["STRONG",{},["'+messages.shareButton+'"]],"', '",["STRONG",{},["'+messages.edit+'"]],"', '",["STRONG",{},["'+messages.view+'"]],"'])+'"]],["LI",{},["'+messages.readme_cat2_l2+'"]]]],["P",{},[["BR",{},[]]]],["H2",{},["'+messages.readme_cat3+'"]],["UL",{},[["LI",{},["'+messages.readme_cat3_l1+'"]],["LI",{},["'+messages.readme_cat3_l2+'"]],["LI",{},["'+messages.readme_cat3_l3+'",["BR",{},[]]]]]]],' +
|
2017-02-17 00:22:45 +08:00
|
|
|
'{"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
|
|
|
}());
|