mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
ELECTRON-656 (Localize context menu labels) (#472)
- Localize context menu labels - Update condition to setLocale for pop-out window
This commit is contained in:
parent
c4726a9dc2
commit
1695920d24
@ -32,6 +32,7 @@ const KeyCodes = {
|
|||||||
let Search;
|
let Search;
|
||||||
let SearchUtils;
|
let SearchUtils;
|
||||||
let CryptoLib;
|
let CryptoLib;
|
||||||
|
let spellChecker;
|
||||||
let isAltKey = false;
|
let isAltKey = false;
|
||||||
let isMenuOpen = false;
|
let isMenuOpen = false;
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ function loadSpellChecker() {
|
|||||||
const SpellCheckerHelper = require('../spellChecker').SpellCheckHelper;
|
const SpellCheckerHelper = require('../spellChecker').SpellCheckHelper;
|
||||||
/* eslint-enable global-require */
|
/* eslint-enable global-require */
|
||||||
// Method to initialize spell checker
|
// Method to initialize spell checker
|
||||||
const spellChecker = new SpellCheckerHelper();
|
spellChecker = new SpellCheckerHelper();
|
||||||
spellChecker.initializeSpellChecker();
|
spellChecker.initializeSpellChecker();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
@ -492,6 +493,10 @@ function createAPI() {
|
|||||||
if (dataObj.titleBar) {
|
if (dataObj.titleBar) {
|
||||||
titleBar.updateLocale(dataObj.titleBar);
|
titleBar.updateLocale(dataObj.titleBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dataObj.contextMenu && spellChecker) {
|
||||||
|
spellChecker.updateContextMenuLocale(dataObj.contextMenu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,12 +29,47 @@ class SpellCheckHelper {
|
|||||||
this.spellCheckHandler.switchLanguage(sysLocale);
|
this.spellCheckHandler.switchLanguage(sysLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextMenuBuilder = new ContextMenuBuilder(this.spellCheckHandler, null, false, SpellCheckHelper.processMenu);
|
this.contextMenuBuilder = new ContextMenuBuilder(this.spellCheckHandler, null, false, this.processMenu.bind(this));
|
||||||
this.contextMenuListener = new ContextMenuListener((info) => {
|
this.contextMenuListener = new ContextMenuListener((info) => {
|
||||||
contextMenuBuilder.showPopupMenu(info);
|
this.contextMenuBuilder.showPopupMenu(info);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the locale for context menu labels
|
||||||
|
* @param content {Object} - locale content for context menu
|
||||||
|
*/
|
||||||
|
updateContextMenuLocale(content) {
|
||||||
|
this.localeContent = content;
|
||||||
|
this.contextMenuBuilder.setAlternateStringFormatter(SpellCheckHelper.getStringTable(content));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the string table for context menu
|
||||||
|
*
|
||||||
|
* @param content {Object} - locale content for context menu
|
||||||
|
* @return {Object} - String table for context menu
|
||||||
|
*/
|
||||||
|
static getStringTable(content) {
|
||||||
|
return {
|
||||||
|
copyMail: () => content['Copy Email Address'] || `Copy Email Address`,
|
||||||
|
copyLinkUrl: () => content['Copy Link'] || 'Copy Link',
|
||||||
|
openLinkUrl: () => content['Open Link'] || 'Open Link',
|
||||||
|
copyImageUrl: () => content['Copy Image URL'] || 'Copy Image URL',
|
||||||
|
copyImage: () => content['Copy Image'] || 'Copy Image',
|
||||||
|
addToDictionary: () => content['Add to Dictionary'] || 'Add to Dictionary',
|
||||||
|
lookUpDefinition: (lookup) => {
|
||||||
|
const lookUp = content['Look Up '] || 'Look Up ';
|
||||||
|
return `${lookUp}"${lookup.word}"`;
|
||||||
|
},
|
||||||
|
searchGoogle: () => content['Search with Google'] || 'Search with Google',
|
||||||
|
cut: () => content.Cut || 'Cut',
|
||||||
|
copy: () => content.Copy || 'Copy',
|
||||||
|
paste: () => content.Paste || 'Paste',
|
||||||
|
inspectElement: () => content['Inspect Element'] || 'Inspect Element',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to add default menu items to the
|
* Method to add default menu items to the
|
||||||
* menu that was generated by ContextMenuBuilder
|
* menu that was generated by ContextMenuBuilder
|
||||||
@ -45,7 +80,7 @@ class SpellCheckHelper {
|
|||||||
* @param menu
|
* @param menu
|
||||||
* @returns menu
|
* @returns menu
|
||||||
*/
|
*/
|
||||||
static processMenu(menu) {
|
processMenu(menu) {
|
||||||
|
|
||||||
let isLink = false;
|
let isLink = false;
|
||||||
menu.items.map((item) => {
|
menu.items.map((item) => {
|
||||||
@ -60,7 +95,7 @@ class SpellCheckHelper {
|
|||||||
menu.append(new MenuItem({
|
menu.append(new MenuItem({
|
||||||
role: 'reload',
|
role: 'reload',
|
||||||
accelerator: 'CmdOrCtrl+R',
|
accelerator: 'CmdOrCtrl+R',
|
||||||
label: 'Reload'
|
label: this.localeContent && this.localeContent.Reload || 'Reload',
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
return menu;
|
return menu;
|
||||||
|
@ -987,22 +987,28 @@ eventEmitter.on('notificationSettings', (notificationSettings) => {
|
|||||||
*/
|
*/
|
||||||
function setLocale(browserWindow, opts) {
|
function setLocale(browserWindow, opts) {
|
||||||
const language = opts && opts.language || app.getLocale();
|
const language = opts && opts.language || app.getLocale();
|
||||||
|
const localeContent = {};
|
||||||
log.send(logLevels.INFO, `language changed to ${language}. Updating menu and user config`);
|
log.send(logLevels.INFO, `language changed to ${language}. Updating menu and user config`);
|
||||||
|
|
||||||
setLanguage(language);
|
setLanguage(language);
|
||||||
if (browserWindow && isMainWindow(browserWindow)) {
|
if (browserWindow && !browserWindow.isDestroyed()) {
|
||||||
menu = electron.Menu.buildFromTemplate(getTemplate(app));
|
if (isMainWindow(browserWindow)) {
|
||||||
electron.Menu.setApplicationMenu(menu);
|
|
||||||
|
|
||||||
if (isWindows10()) {
|
menu = electron.Menu.buildFromTemplate(getTemplate(app));
|
||||||
browserWindow.setMenuBarVisibility(false);
|
electron.Menu.setApplicationMenu(menu);
|
||||||
|
|
||||||
// update locale for custom title bar
|
if (isWindows10()) {
|
||||||
if (isCustomTitleBarEnabled) {
|
browserWindow.setMenuBarVisibility(false);
|
||||||
const titleBarContent = i18n.getMessageFor('TitleBar');
|
|
||||||
browserWindow.webContents.send('locale-changed', { titleBar: titleBarContent });
|
// update locale for custom title bar
|
||||||
|
if (isCustomTitleBarEnabled) {
|
||||||
|
localeContent.titleBar = i18n.getMessageFor('TitleBar');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localeContent.contextMenu = i18n.getMessageFor('ContextMenu');
|
||||||
|
browserWindow.webContents.send('locale-changed', localeContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateConfigField('locale', language);
|
updateConfigField('locale', language);
|
||||||
|
@ -17,6 +17,21 @@
|
|||||||
"Bring to Front on Notifications": "Bring to Front on Notifications",
|
"Bring to Front on Notifications": "Bring to Front on Notifications",
|
||||||
"Certificate Error": "Certificate Error",
|
"Certificate Error": "Certificate Error",
|
||||||
"Close": "Close",
|
"Close": "Close",
|
||||||
|
"ContextMenu": {
|
||||||
|
"Add to Dictionary": "Add to Dictionary",
|
||||||
|
"Copy": "Copy",
|
||||||
|
"Copy Email Address": "Copy Email Address",
|
||||||
|
"Copy Image": "Copy Image",
|
||||||
|
"Copy Image URL": "Copy Image URL",
|
||||||
|
"Copy Link": "Copy Link",
|
||||||
|
"Cut": "Cut",
|
||||||
|
"Inspect Element": "Inspect Element",
|
||||||
|
"Look Up ": "Look Up ",
|
||||||
|
"Open Link": "Open Link",
|
||||||
|
"Paste": "Paste",
|
||||||
|
"Reload": "Reload",
|
||||||
|
"Search with Google": "Search with Google"
|
||||||
|
},
|
||||||
"Copy": "Copy",
|
"Copy": "Copy",
|
||||||
"Custom": "Custom",
|
"Custom": "Custom",
|
||||||
"Cut": "Cut",
|
"Cut": "Cut",
|
||||||
|
@ -17,6 +17,21 @@
|
|||||||
"Bring to Front on Notifications": "Bring to Front on Notifications",
|
"Bring to Front on Notifications": "Bring to Front on Notifications",
|
||||||
"Certificate Error": "Certificate Error",
|
"Certificate Error": "Certificate Error",
|
||||||
"Close": "Close",
|
"Close": "Close",
|
||||||
|
"ContextMenu": {
|
||||||
|
"Add to Dictionary": "Add to Dictionary",
|
||||||
|
"Copy": "Copy",
|
||||||
|
"Copy Email Address": "Copy Email Address",
|
||||||
|
"Copy Image": "Copy Image",
|
||||||
|
"Copy Image URL": "Copy Image URL",
|
||||||
|
"Copy Link": "Copy Link",
|
||||||
|
"Cut": "Cut",
|
||||||
|
"Inspect Element": "Inspect Element",
|
||||||
|
"Look Up ": "Look Up ",
|
||||||
|
"Open Link": "Open Link",
|
||||||
|
"Paste": "Paste",
|
||||||
|
"Reload": "Reload",
|
||||||
|
"Search with Google": "Search with Google"
|
||||||
|
},
|
||||||
"Copy": "Copy",
|
"Copy": "Copy",
|
||||||
"Custom": "Custom",
|
"Custom": "Custom",
|
||||||
"Cut": "Cut",
|
"Cut": "Cut",
|
||||||
|
@ -17,6 +17,21 @@
|
|||||||
"Bring to Front on Notifications": "通知時に前面に表示",
|
"Bring to Front on Notifications": "通知時に前面に表示",
|
||||||
"Certificate Error": "証明書のエラー",
|
"Certificate Error": "証明書のエラー",
|
||||||
"Close": "閉じる",
|
"Close": "閉じる",
|
||||||
|
"ContextMenu": {
|
||||||
|
"Add to Dictionary": "辞書に追加",
|
||||||
|
"Copy": "コピー",
|
||||||
|
"Copy Email Address": "メールアドレスをコピーする",
|
||||||
|
"Copy Image": "イメージをコピーする",
|
||||||
|
"Copy Image URL": "コピー画像のURL",
|
||||||
|
"Copy Link": "リンクをコピーする",
|
||||||
|
"Cut": "カット",
|
||||||
|
"Inspect Element": "要素の検査",
|
||||||
|
"Look Up ": "見上げる",
|
||||||
|
"Open Link": "リンクを開く",
|
||||||
|
"Paste": "ペースト",
|
||||||
|
"Reload": "リロード",
|
||||||
|
"Search with Google": "Googleで検索"
|
||||||
|
},
|
||||||
"Copy": "コピー",
|
"Copy": "コピー",
|
||||||
"Custom": "カスタム",
|
"Custom": "カスタム",
|
||||||
"Cut": "切り取り",
|
"Cut": "切り取り",
|
||||||
|
@ -17,6 +17,21 @@
|
|||||||
"Bring to Front on Notifications": "通知時に前面に表示",
|
"Bring to Front on Notifications": "通知時に前面に表示",
|
||||||
"Certificate Error": "証明書のエラー",
|
"Certificate Error": "証明書のエラー",
|
||||||
"Close": "閉じる",
|
"Close": "閉じる",
|
||||||
|
"ContextMenu": {
|
||||||
|
"Add to Dictionary": "辞書に追加",
|
||||||
|
"Copy": "コピー",
|
||||||
|
"Copy Email Address": "メールアドレスをコピーする",
|
||||||
|
"Copy Image": "イメージをコピーする",
|
||||||
|
"Copy Image URL": "コピー画像のURL",
|
||||||
|
"Copy Link": "リンクをコピーする",
|
||||||
|
"Cut": "カット",
|
||||||
|
"Inspect Element": "要素の検査",
|
||||||
|
"Look Up ": "見上げる",
|
||||||
|
"Open Link": "リンクを開く",
|
||||||
|
"Paste": "ペースト",
|
||||||
|
"Reload": "リロード",
|
||||||
|
"Search with Google": "Googleで検索"
|
||||||
|
},
|
||||||
"Copy": "コピー",
|
"Copy": "コピー",
|
||||||
"Custom": "カスタム",
|
"Custom": "カスタム",
|
||||||
"Cut": "切り取り",
|
"Cut": "切り取り",
|
||||||
|
Loading…
Reference in New Issue
Block a user