chore: remove language specific checks and add missing license

This commit is contained in:
yflory 2026-04-27 15:09:40 +02:00
parent 5354adfea1
commit 87548d4ba3
9 changed files with 34 additions and 44 deletions

View File

@ -29,8 +29,8 @@ var map = {
'sv': 'Svenska',
//'te': 'తెలుగు',
'uk': 'Українська',
'zh_Hans': '中文(簡體)',
'zh_Hant': '中文(正體)',
'zh': '中文(簡體)', // simplified
'zh_Hant': '中文(正體)', // traditional
};
var Messages = {};
@ -40,55 +40,34 @@ var getBrowserLanguage = function () { return navigator.language || navigator.us
// Normalize browser/localStorage language labels to CryptPad internal keys.
// We keep this centralized to avoid scattered `if (l === 'zh') ...` logic.
var langAliases = {
'zh': 'zh_Hans',
'zh-cn': 'zh_Hans',
'zh-sg': 'zh_Hans',
'zh-hans': 'zh_Hans',
'zh_hans': 'zh_Hans',
'zh-cn': 'zh',
'zh-sg': 'zh',
'zh-hans': 'zh',
'zh-tw': 'zh_Hant',
'zh-hk': 'zh_Hant',
'zh-mo': 'zh_Hant',
'zh-hant': 'zh_Hant',
'zh_hant': 'zh_Hant'
};
var normalizeLanguage = function (l) {
if (!l) { return l; }
// If it already matches a supported internal key, return as-is.
if (map[l]) { return l; }
var lLower = String(l).toLowerCase();
var lLower = String(l).toLowerCase().replace('_', '-');
return langAliases[lLower] || l;
};
var getLanguage = Messages._getLanguage = function () {
if (window.cryptpadLanguage) {
var original = window.cryptpadLanguage;
var normalized = normalizeLanguage(original);
// Migrate legacy localStorage language key.
if (original === 'zh' && normalized === 'zh_Hans') {
try { localStorage.setItem(LS_LANG, 'zh_Hans'); } catch (e) { console.log(e); }
}
window.cryptpadLanguage = normalized;
return normalized;
}
if (window.cryptpadLanguage) { return window.cryptpadLanguage; }
var l = getBrowserLanguage();
try {
l = getStoredLanguage() || getBrowserLanguage();
} catch (e) { console.log(e); }
var originalLang = l;
l = normalizeLanguage(l);
// Migrate legacy localStorage language key.
if (originalLang === 'zh' && l === 'zh_Hans') {
try { localStorage.setItem(LS_LANG, 'zh_Hans'); } catch (e) { console.log(e); }
}
if (map[l]) { return l; }
var dash = (l || '').split('-')[0];
var under = (l || '').split('_')[0];
if (map[dash]) { return dash; }
if (map[under]) { return under; }
return 'en';
return map[l] ? l :
(map[l.split('-')[0]] ? l.split('-')[0] :
(map[l.split('_')[0]] ? l.split('_')[0] : 'en'));
};
var language = getLanguage();
window.cryptpadLanguage = language;
@ -103,8 +82,6 @@ var reqPaths = {
Object.keys(map).forEach(function (k) {
reqPaths["/common/translations/messages."+k+".js"] = "json!/common/translations/messages."+k+".json";
});
// Legacy locale key for Simplified Chinese (before zh_Hans)
reqPaths["/common/translations/messages.zh.js"] = "json!/common/translations/messages.zh_Hans.json";
require.config({
map: {
"*": reqPaths

View File

@ -9,9 +9,10 @@
* If you want to check all the existing translation keys, you can open the internal language file
but you should not change it directly (/common/translations/messages.{LANG}.js)
*/
define(['/common/translations/messages.zh_Hans.js'], function (Messages) {
define(['/common/translations/messages.zh.js'], function (Messages) {
// Replace the existing keys in your copied file here:
// Messages.button_newpad = "New Rich Text Document";
return Messages;
});

View File

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2026 XWiki CryptPad Team <contact@cryptpad.org> and contributors
//
// SPDX-License-Identifier: AGPL-3.0-or-later
/*
* You can override the translation text using this file.
* The recommended method is to make a copy of this file (/customize.dist/translations/messages.{LANG}.js)
in a 'customize' directory (/customize/translations/messages.{LANG}.js).
* If you want to check all the existing translation keys, you can open the internal language file
but you should not change it directly (/common/translations/messages.{LANG}.js)
*/
define(['/common/translations/messages.zh_Hant.js'], function (Messages) {
// Replace the existing keys in your copied file here:
// Messages.button_newpad = "New Rich Text Document";
return Messages;
});

View File

@ -51,8 +51,6 @@ try {
}
var preferredLanguage = config.preferredLanguage;
var langAliases = { 'zh': 'zh_Hans' };
if (langAliases[preferredLanguage]) { preferredLanguage = langAliases[preferredLanguage]; }
var Preferred;
var noScriptContent = [ Messages.ui_jsRequired ];

View File

@ -67,8 +67,6 @@ const factory = (Feedback, Hash, Util,
var migrateLanguage = function () {
if (!localStorage.CRYPTPAD_LANG) { return; }
var l = localStorage.CRYPTPAD_LANG;
var langAliases = { 'zh': 'zh_Hans' };
if (langAliases[l]) { l = langAliases[l]; }
userObject.settings.language = l;
};
if (version < 3) {

View File

@ -262,11 +262,7 @@ define([
if (!isRegister && !isProxyEmpty(rt.proxy)) {
var l = Util.find(rt.proxy, ['settings', 'general', 'language']);
var LS_LANG = "CRYPTPAD_LANG";
if (l) {
var langAliases = { 'zh': 'zh_Hans' };
if (langAliases[l]) { l = langAliases[l]; }
localStorage.setItem(LS_LANG, l);
}
if (l) { localStorage.setItem(LS_LANG, l); }
return void LocalStore.login(undefined, res.blockHash, res.uname, function () {
cb(void 0, res, RT);

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2026 XWiki CryptPad Team <contact@cryptpad.org> and contributors
SPDX-License-Identifier: AGPL-3.0-or-later