Wrap all strings in _td function for i18n

This commit is contained in:
Germain Souquet
2021-04-23 16:56:17 +01:00
parent 1ff5387f1d
commit 658304cc51
8 changed files with 394 additions and 27 deletions

View File

@@ -57,6 +57,8 @@ try {
}
}
const { _td } = require('./language-helper');
let seshatSupported = false;
let Seshat;
let SeshatRecovery;
@@ -268,8 +270,8 @@ const warnBeforeExit = (event, input) => {
if (shouldWarnBeforeExit && exitShortcutPressed) {
const shouldCancelCloseRequest = dialog.showMessageBoxSync(mainWindow, {
type: "question",
buttons: ["Cancel", "Close Element"],
message: "Are you sure you want to quit?",
buttons: [_td("Cancel"), _td("Close Element")],
message: _td("Are you sure you want to quit?"),
defaultId: 1,
cancelId: 0,
}) === 0;

View File

@@ -0,0 +1,30 @@
{
"Cancel": "Cancel",
"Close Element": "Close Element",
"Are you sure you want to quit?": "Are you sure you want to quit?",
"Show/Hide": "Show/Hide",
"Quit": "Quit",
"Edit": "Edit",
"View": "View",
"Preferences": "Preferences",
"Window": "Window",
"Help": "Help",
"Element Help": "Element Help",
"Speech": "Speech",
"Close": "Close",
"Minimize": "Minimize",
"Zoom": "Zoom",
"Bring All to Front": "Bring All to Front",
"File": "File",
"Copy image": "Copy image",
"Copy email address": "Copy email address",
"Copy link address": "Copy link address",
"Save image as...": "Save image as...",
"Failed to save image": "Failed to save image",
"The image failed to save": "The image failed to save",
"Add to dictionary": "Add to dictionary",
"Cut": "Cut",
"Copy": "Copy",
"Paste": "Paste",
"Select All": "Select All"
}

11
src/language-helper.js Normal file
View File

@@ -0,0 +1,11 @@
// Function which only purpose is to mark that a string is translatable
// Does not actually do anything. It's helpful for automatic extraction of translatable strings
function _td(s) {
return s;
}
module.exports = {
_td,
};

View File

@@ -19,6 +19,7 @@ const {app, Tray, Menu, nativeImage} = require('electron');
const pngToIco = require('png-to-ico');
const path = require('path');
const fs = require('fs');
const { _td } = require('./language-helper');
let trayIcon = null;
@@ -49,12 +50,12 @@ exports.create = function(config) {
const contextMenu = Menu.buildFromTemplate([
{
label: `Show/Hide ${config.brand}`,
label: _td('Show/Hide'),
click: toggleWin,
},
{ type: 'separator' },
{
label: 'Quit',
label: _td('Quit'),
click: function() {
app.quit();
},

View File

@@ -15,11 +15,13 @@ limitations under the License.
*/
const {app, shell, Menu} = require('electron');
const { _td } = require('./language-helper');
// Menu template from http://electron.atom.io/docs/api/menu/, edited
const template = [
{
label: '&Edit',
label: _td('Edit'),
accelerator: 'e',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
@@ -33,7 +35,8 @@ const template = [
],
},
{
label: '&View',
label: _td('View'),
accelerator: 'V',
submenu: [
{ type: 'separator' },
{ role: 'resetzoom' },
@@ -41,7 +44,7 @@ const template = [
{ role: 'zoomout' },
{ type: 'separator' },
{
label: 'Preferences',
label: _td('Preferences'),
accelerator: 'Command+,', // Mac-only accelerator
click() { global.mainWindow.webContents.send('preferences'); },
},
@@ -50,7 +53,8 @@ const template = [
],
},
{
label: '&Window',
label: _td('Window'),
accelerator: 'w',
role: 'window',
submenu: [
{ role: 'minimize' },
@@ -58,11 +62,12 @@ const template = [
],
},
{
label: '&Help',
label: _td('Help'),
accelerator: 'h',
role: 'help',
submenu: [
{
label: 'Element Help',
label: _td('Element Help'),
click() { shell.openExternal('https://element.io/help'); },
},
],
@@ -94,7 +99,7 @@ if (process.platform === 'darwin') {
template[1].submenu.push(
{ type: 'separator' },
{
label: 'Speech',
label: _td('Speech'),
submenu: [
{ role: 'startspeaking' },
{ role: 'stopspeaking' },
@@ -105,30 +110,31 @@ if (process.platform === 'darwin') {
// This also has specific functionality on macOS
template[3].submenu = [
{
label: 'Close',
label: _td('Close'),
accelerator: 'CmdOrCtrl+W',
role: 'close',
},
{
label: 'Minimize',
label: _td('Minimize'),
accelerator: 'CmdOrCtrl+M',
role: 'minimize',
},
{
label: 'Zoom',
label: _td('Zoom'),
role: 'zoom',
},
{
type: 'separator',
},
{
label: 'Bring All to Front',
label: _td('Bring All to Front'),
role: 'front',
},
];
} else {
template.unshift({
label: '&File',
label: _td('File'),
accelerator: 'f',
submenu: [
// For some reason, 'about' does not seem to work on windows.
/*{

View File

@@ -3,6 +3,7 @@ const url = require('url');
const fs = require('fs');
const request = require('request');
const path = require('path');
const { _td } = require('./language-helper');
const MAILTO_PREFIX = "mailto:";
@@ -73,7 +74,8 @@ function onLinkContextMenu(ev, params) {
if (params.hasImageContents) {
popupMenu.append(new MenuItem({
label: '&Copy image',
label: _td('Copy image'),
accelerator: 'c',
click() {
ev.sender.copyImageAt(params.x, params.y);
},
@@ -85,14 +87,16 @@ function onLinkContextMenu(ev, params) {
// Special-case e-mail URLs to strip the `mailto:` like modern browsers do
if (url.startsWith(MAILTO_PREFIX)) {
popupMenu.append(new MenuItem({
label: 'Copy email &address',
label: _td('Copy email address'),
accelerator: 'a',
click() {
clipboard.writeText(url.substr(MAILTO_PREFIX.length));
},
}));
} else {
popupMenu.append(new MenuItem({
label: 'Copy link &address',
label: _td('Copy link address'),
accelerator: 'a',
click() {
clipboard.writeText(url);
},
@@ -104,7 +108,8 @@ function onLinkContextMenu(ev, params) {
// only the renderer can resolve them so don't give the user an option to.
if (params.hasImageContents && !url.startsWith('blob:')) {
popupMenu.append(new MenuItem({
label: 'Sa&ve image as...',
label: _td('Save image as...'),
accelerator: 'a',
async click() {
const targetFileName = params.titleText || "image.png";
const {filePath} = await dialog.showSaveDialog({
@@ -123,8 +128,8 @@ function onLinkContextMenu(ev, params) {
console.error(err);
dialog.showMessageBox({
type: "error",
title: "Failed to save image",
message: "The image failed to save",
title: _td("Failed to save image"),
message: _td("The image failed to save"),
});
}
},
@@ -151,7 +156,7 @@ function _CutCopyPasteSelectContextMenus(params) {
options.push({
type: 'separator',
}, {
label: 'Add to dictionary',
label: _td('Add to dictionary'),
click: (menuItem, browserWindow) => {
browserWindow.webContents.session.addWordToSpellCheckerDictionary(params.misspelledWord);
},
@@ -162,22 +167,26 @@ function _CutCopyPasteSelectContextMenus(params) {
options.push({
role: 'cut',
label: 'Cu&t',
label: _td('Cut'),
accelerator: 't',
enabled: params.editFlags.canCut,
}, {
role: 'copy',
label: '&Copy',
label: _td('Copy'),
accelerator: 'c',
enabled: params.editFlags.canCopy,
}, {
role: 'paste',
label: '&Paste',
label: _td('Paste'),
accelerator: 'p',
enabled: params.editFlags.canPaste,
}, {
role: 'pasteandmatchstyle',
enabled: params.editFlags.canPaste,
}, {
role: 'selectall',
label: "Select &All",
label: _td("Select All"),
accelerator: 'a',
enabled: params.editFlags.canSelectAll,
});
return options;