Move temporary translation keys to a single file

This commit is contained in:
yflory 2024-03-25 17:52:03 +01:00
parent 5337ff165d
commit 7afee532ff
6 changed files with 183 additions and 191 deletions

View File

@ -29,11 +29,11 @@ var map = {
'zh': '中文(簡體)',
};
var messages = {};
var Messages = {};
var LS_LANG = "CRYPTPAD_LANG";
var getStoredLanguage = function () { return localStorage && localStorage.getItem(LS_LANG); };
var getBrowserLanguage = function () { return navigator.language || navigator.userLanguage || ''; };
var getLanguage = messages._getLanguage = function () {
var getLanguage = Messages._getLanguage = function () {
if (window.cryptpadLanguage) { return window.cryptpadLanguage; }
try {
if (getStoredLanguage()) { return getStoredLanguage(); }
@ -103,19 +103,19 @@ define(req, function(AppConfig, Default, Language) {
}
};
extend(messages, Default);
extend(Messages, Default);
if (Language && language !== defaultLanguage) {
// Add the translated keys to the returned object
extend(messages, Language);
extend(Messages, Language);
}
messages._languages = map;
messages._languageUsed = language;
Messages._languages = map;
Messages._languageUsed = language;
// Get keys with parameters
messages._getKey = function (key, argArray) {
if (!messages[key]) { return '?'; }
var text = messages[key];
Messages._getKey = function (key, argArray) {
if (!Messages[key]) { return '?'; }
var text = Messages[key];
if (typeof(text) === 'string') {
return text.replace(/\{(\d+)\}/g, function (str, p1) {
if (typeof(argArray[p1]) === 'string' || typeof(argArray[p1]) === "number") {
@ -129,7 +129,86 @@ define(req, function(AppConfig, Default, Language) {
}
};
return messages;
// XXX Temporary keys
Messages.admin_cat_customize = "Customize";
Messages.admin_cat_security = "Security";
Messages.admin_logoTitle = "Custom Logo";
Messages.admin_logoHint = "SVG, PNG or JPG, maximum size 200KB";
Messages.admin_logoButton = "Upload new";
Messages.admin_logoRemoveButton = "Restore default";
Messages.admin_colorTitle = "Accent color";
Messages.admin_colorHint = "Change the accent color of your CryptPad instance. Please ensure text and buttons are readable with sufficient contrast in both light and dark themes.";
Messages.admin_colorCurrent = "Current accent color";
Messages.admin_colorChange = "Change color";
Messages.admin_colorPick = "Pick a color";
Messages.admin_colorPreview = "Preview color";
Messages.admin_supportSetupHint = "Create or update the support keys.";
Messages.admin_supportSetupTitle = "Initialize support";
Messages.admin_supportEnabled = "Modern support system is enabled.";
Messages.admin_supportDisabled = "Modern support system is disabled.";
Messages.admin_supportInit = "Initialize support page on this instance";
Messages.admin_supportDelete = "Disable support";
Messages.admin_supportConfirm = "Are you sure? This will delete all existing tickets and block access for all moderators.";
Messages.admin_supportMembers = "Support team";
Messages.admin_supportAdd = "Add a contact to the support team";
Messages.admin_supportRotateNotify = "Warning: new keys have been generated but an unenexpected error prevented the system to send them to the moderators. Please remove and re-add all members of the support team";
Messages.admin_supportTeamTitle = "admin_supportTeamTitle";
Messages.admin_supportTeamHint = "admin_supportTeamHint";
Messages.admin_supportOpen = "Open helpdesk";
Messages.support_userNotification = "New support ticket or response: {0}";
Messages.support_moderatorNotification = "You have been added to the moderators list";
Messages.moderationPage = "Support mailbox"; // XXX
Messages.support_cat_open = "Inbox";
Messages.support_cat_closed = "Closed";
Messages.support_cat_search = "Search";
Messages.support_cat_settings = "Settings";
Messages.support_cat_legacy = "Legacy";
Messages.support_pending = "Archived tickets:";
Messages.support_pending_tag = "Archived";
Messages.support_active_tag = "Inbox";
Messages.support_closed_tag = "Closed";
Messages.support_privacyTitle = "Answer anonymously";
Messages.support_privacyHint = "Check this option to reply as 'The Support Team' instead of your own username";
Messages.support_notificationsTitle = "Disable notifications";
Messages.support_notificationsHint = "Check this option to disable notifications for new tickets and replies";
Messages.support_openTicketTitle = "Open a ticket with a user";
Messages.support_openTicketHint = "Copy the recipient user's data from their profile page or an existing support ticket. They will receive a CryptPad notification about this message.";
Messages.support_userChannel = "User's notifications channel ID";
Messages.support_userKey = "User's public key";
Messages.support_invalChan = "Invalid notifications channel";
Messages.support_pasteUserData = "Paste user data here";
Messages.support_recordedTitle = "Snippets";
Messages.support_recordedHint = "Store common text as one-click shortcuts to insert in support messages.";
Messages.support_recordedEmpty = "No snippets";
Messages.support_recordedId = "Snippet ID (unique)";
Messages.support_recordedContent = "Content";
Messages.support_legacyTitle = "View old support data";
Messages.support_legacyHint = "View tickets from the legacy support system and recreate them in the new one.";
Messages.support_legacyButton = "Get active";
Messages.support_legacyDump = "Export all";
Messages.support_legacyClear = "Delete from my account";
Messages.support_searchLabel = "Search (title or ticketId)";
Messages.support_team = "The Support Team"; // XXX
Messages.support_answerAs = "Answering as <b>{0}</b>"; // XXX
Messages.support_movePending = "Move to archive";
Messages.support_moveActive = "Move to active";
Messages.support_copyUserData = "Copy user data";
Messages.support_insertRecorded = "Insert snippet";
return Messages;
});
}());

View File

@ -769,20 +769,6 @@ define([
cb(form);
});
// XXX
Messages.admin_cat_customize = "Customize";
Messages.admin_cat_security = "Security";
Messages.admin_logoTitle = "Custom Logo";
Messages.admin_logoHint = "SVG, PNG or JPG, maximum size 200KB";
Messages.admin_logoButton = "Upload new";
Messages.admin_logoRemoveButton = "Restore default";
Messages.admin_colorTitle = "Accent color";
Messages.admin_colorHint = "Change the accent color of your CryptPad instance. Please ensure text and buttons are readable with sufficient contrast in both light and dark themes.";
Messages.admin_colorCurrent = "Current accent color";
Messages.admin_colorChange = "Change color";
Messages.admin_colorPick = "Pick a color";
Messages.admin_colorPreview = "Preview color";
sidebar.addItem('logo', (cb) => {
// Msg.admin_logoHint, Msg.admin_logoTitle
@ -2689,115 +2675,6 @@ define([
cb(form);
});
var getApi = function (cb) {
return function () {
require(['/api/broadcast?'+ (+new Date())], function (Broadcast) {
cb(Broadcast);
setTimeout(function () {
try {
var ctx = require.s.contexts._;
var defined = ctx.defined;
Object.keys(defined).forEach(function (href) {
if (/^\/api\/broadcast\?[0-9]{13}/.test(href)) {
delete defined[href];
return;
}
});
} catch (e) {}
});
});
};
};
var checkLastBroadcastHash = function (cb) {
var deleted = [];
require(['/api/broadcast?'+ (+new Date())], function (BCast) {
var hash = BCast.lastBroadcastHash || '1'; // Truthy value if no lastKnownHash
common.mailbox.getNotificationsHistory('broadcast', null, hash, function (e, msgs) {
if (e) { console.error(e); return void cb(e); }
// No history, nothing to change
if (!Array.isArray(msgs)) { return void cb(); }
if (!msgs.length) { return void cb(); }
var lastHash;
var next = false;
// Start from the most recent messages until you find a CUSTOM message and
// check if it has been deleted
msgs.reverse().some(function (data) {
var c = data.content;
// This is the hash we want to keep
if (next) {
if (!c || !c.hash) { return; }
lastHash = c.hash;
next = false;
return true;
}
// initialize with the most recent hash
if (!lastHash && c && c.hash) { lastHash = c.hash; }
var msg = c && c.msg;
if (!msg) { return; }
// Remember all deleted messages
if (msg.type === "BROADCAST_DELETE") {
deleted.push(Util.find(msg, ['content', 'uid']));
}
// Only check custom messages
if (msg.type !== "BROADCAST_CUSTOM") { return; }
// If the most recent CUSTOM message has been deleted, it means we don't
// need to keep any message and we can continue with lastHash as the most
// recent broadcast message.
if (deleted.indexOf(msg.uid) !== -1) { return true; }
// We just found the oldest message we want to keep, move one iteration
// further into the loop to get the next message's hash.
// If this is the end of the loop, don't bump lastBroadcastHash at all.
next = true;
});
// If we don't have to bump our lastBroadcastHash, abort
if (next) { return void cb(); }
// Otherwise, bump to lastHash
console.warn('Updating last broadcast hash to', lastHash);
sFrameChan.query('Q_ADMIN_RPC', {
cmd: 'ADMIN_DECREE',
data: ['SET_LAST_BROADCAST_HASH', [lastHash]]
}, function (e, response) {
if (e || response.error) {
UI.warn(Messages.error);
console.error(e, response);
return;
}
console.log('lastBroadcastHash updated');
if (typeof(cb) === "function") { cb(); }
});
});
});
};
// XXX
Messages.admin_supportSetupHint = "Create or update the support keys.";
Messages.admin_supportSetupTitle = "Initialize support";
Messages.admin_supportEnabled = "Modern support system is enabled.";
Messages.admin_supportDisabled = "Modern support system is disabled.";
Messages.admin_supportInit = "Initialize support page on this instance";
Messages.admin_supportDelete = "Disable support";
Messages.admin_supportConfirm = "Are you sure? This will delete all existing tickets and block access for all moderators.";
Messages.admin_supportMembers = "Support team";
Messages.admin_supportAdd = "Add a contact to the support team";
Messages.admin_supportRotateNotify = "Warning: new keys have been generated but an unenexpected error prevented the system to send them to the moderators. Please remove and re-add all members of the support team";
Messages.admin_supportTeamTitle = "admin_supportTeamTitle";
Messages.admin_supportTeamHint = "admin_supportTeamHint";
Messages.admin_supportOpen = "Open helpdesk";
let onRefreshSupportEvt = Util.mkEvent();
let refreshSupport = () => {
let moderators, supportKey;
@ -3069,6 +2946,99 @@ define([
});
setTimeout(refreshSupport);
var getApi = function (cb) {
return function () {
require(['/api/broadcast?'+ (+new Date())], function (Broadcast) {
cb(Broadcast);
setTimeout(function () {
try {
var ctx = require.s.contexts._;
var defined = ctx.defined;
Object.keys(defined).forEach(function (href) {
if (/^\/api\/broadcast\?[0-9]{13}/.test(href)) {
delete defined[href];
return;
}
});
} catch (e) {}
});
});
};
};
var checkLastBroadcastHash = function (cb) {
var deleted = [];
require(['/api/broadcast?'+ (+new Date())], function (BCast) {
var hash = BCast.lastBroadcastHash || '1'; // Truthy value if no lastKnownHash
common.mailbox.getNotificationsHistory('broadcast', null, hash, function (e, msgs) {
if (e) { console.error(e); return void cb(e); }
// No history, nothing to change
if (!Array.isArray(msgs)) { return void cb(); }
if (!msgs.length) { return void cb(); }
var lastHash;
var next = false;
// Start from the most recent messages until you find a CUSTOM message and
// check if it has been deleted
msgs.reverse().some(function (data) {
var c = data.content;
// This is the hash we want to keep
if (next) {
if (!c || !c.hash) { return; }
lastHash = c.hash;
next = false;
return true;
}
// initialize with the most recent hash
if (!lastHash && c && c.hash) { lastHash = c.hash; }
var msg = c && c.msg;
if (!msg) { return; }
// Remember all deleted messages
if (msg.type === "BROADCAST_DELETE") {
deleted.push(Util.find(msg, ['content', 'uid']));
}
// Only check custom messages
if (msg.type !== "BROADCAST_CUSTOM") { return; }
// If the most recent CUSTOM message has been deleted, it means we don't
// need to keep any message and we can continue with lastHash as the most
// recent broadcast message.
if (deleted.indexOf(msg.uid) !== -1) { return true; }
// We just found the oldest message we want to keep, move one iteration
// further into the loop to get the next message's hash.
// If this is the end of the loop, don't bump lastBroadcastHash at all.
next = true;
});
// If we don't have to bump our lastBroadcastHash, abort
if (next) { return void cb(); }
// Otherwise, bump to lastHash
console.warn('Updating last broadcast hash to', lastHash);
sFrameChan.query('Q_ADMIN_RPC', {
cmd: 'ADMIN_DECREE',
data: ['SET_LAST_BROADCAST_HASH', [lastHash]]
}, function (e, response) {
if (e || response.error) {
UI.warn(Messages.error);
console.error(e, response);
return;
}
console.log('lastBroadcastHash updated');
if (typeof(cb) === "function") { cb(); }
});
});
});
};
sidebar.addItem('maintenance', function(cb){
var button = blocks.button('primary', '', Messages.admin_maintenanceButton);
var $button = $(button);

View File

@ -484,9 +484,6 @@ define([
}
};
// XXX
Messages.support_userNotification = "New support ticket or response: {0}";
Messages.support_moderatorNotification = "You have been added to the moderators list";
handlers['NOTIF_TICKET'] = function (common, data) {
var content = data.content;
var msg = content.msg.content;

View File

@ -53,52 +53,6 @@ define([
REFRESH_TAGS: Util.mkEvent()
};
// XXX
Messages.moderationPage = "Support mailbox"; // XXX
Messages.support_cat_open = "Inbox";
Messages.support_cat_closed = "Closed";
Messages.support_cat_search = "Search";
Messages.support_cat_settings = "Settings";
Messages.support_cat_legacy = "Legacy";
Messages.support_pending = "Archived tickets:";
Messages.support_pending_tag = "Archived";
Messages.support_active_tag = "Inbox";
Messages.support_closed_tag = "Closed";
/*
Messages.support_activeListTitle = "Active tickets";
Messages.support_pendingListTitle = "Pending tickets";
Messages.support_activeListHint = "List of tickets that are in an active state";
Messages.support_pendingListHint = "List of tickets that may not be updated for a while but should not be closed";
*/
Messages.support_privacyTitle = "Answer anonymously";
Messages.support_privacyHint = "Check this option to reply as 'The Support Team' instead of your own username";
Messages.support_notificationsTitle = "Disable notifications";
Messages.support_notificationsHint = "Check this option to disable notifications for new tickets and replies";
Messages.support_openTicketTitle = "Open a ticket with a user";
Messages.support_openTicketHint = "Copy the recipient user's data from their profile page or an existing support ticket. They will receive a CryptPad notification about this message.";
Messages.support_userChannel = "User's notifications channel ID";
Messages.support_userKey = "User's public key";
Messages.support_invalChan = "Invalid notifications channel";
Messages.support_pasteUserData = "Paste user data here";
Messages.support_recordedTitle = "Snippets";
Messages.support_recordedHint = "Store common text as one-click shortcuts to insert in support messages.";
Messages.support_recordedEmpty = "No snippets";
Messages.support_recordedId = "Snippet ID (unique)";
Messages.support_recordedContent = "Content";
Messages.support_legacyTitle = "View old support data";
Messages.support_legacyHint = "View tickets from the legacy support system and recreate them in the new one.";
Messages.support_legacyButton = "Get active";
Messages.support_legacyDump = "Export all";
Messages.support_legacyClear = "Delete from my account";
Messages.support_searchLabel = "Search (title or ticketId)";
var andThen = function (common, $container, linkedTicket) {
const sidebar = Sidebar.create(common, 'support', $container);

View File

@ -533,7 +533,6 @@ define([
};
};
Messages.support_copyUserData = "Copy user data"; // XXX Already added in support/ui.js
var addCopyData = function ($container) {
if (!APP.isModerator) { return; }

View File

@ -15,13 +15,6 @@ define([
'/customize/pages.js',
], function ($, ApiConfig, h, UI, Hash, Util, Clipboard, UIElements, Messages, Pages) {
Messages.support_team = "The Support Team"; // XXX
Messages.support_answerAs = "Answering as <b>{0}</b>"; // XXX
Messages.support_movePending = "Move to archive";
Messages.support_moveActive = "Move to active";
Messages.support_copyUserData = "Copy user data";
Messages.support_insertRecorded = "Insert snippet";
var getDebuggingData = function (ctx, data) {
var common = ctx.common;
var metadataMgr = common.getMetadataMgr();
@ -41,7 +34,7 @@ define([
if (ctx.isAdmin && ctx.anonymous) {
data.sender = {
name: Messages.support_team,
accountName: 'support' // XXX hard-coded text? DB
accountName: 'support'
// XXX send edPublic? or keep it private
};
}