diff --git a/js/spellChecker/index.js b/js/spellChecker/index.js index 9bcfe110..b9701dce 100644 --- a/js/spellChecker/index.js +++ b/js/spellChecker/index.js @@ -2,6 +2,7 @@ const { remote } = require('electron'); const { MenuItem } = remote; const { isMac } = require('./../utils/misc'); const { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } = require('electron-spellchecker'); +const stringFormat = require('./../utils/stringFormat'); class SpellCheckHelper { @@ -59,8 +60,8 @@ class SpellCheckHelper { 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}"`; + const formattedString = stringFormat(content['Look Up {searchText}'], { searchText: lookup.word }); + return formattedString || `Look Up ${lookup.word}`; }, searchGoogle: () => content['Search with Google'] || 'Search with Google', cut: () => content.Cut || 'Cut', diff --git a/js/utils/stringFormat.js b/js/utils/stringFormat.js new file mode 100644 index 00000000..9282b2c4 --- /dev/null +++ b/js/utils/stringFormat.js @@ -0,0 +1,22 @@ +/** + * Injects content into string + * @param string {String} + * @param data {Object} - content to replace + * @return {*} + */ +function stringFormat(string, data) { + for (let key in data) { + if (Object.prototype.hasOwnProperty.call(data, key)) { + return string.replace(/({([^}]+)})/g, function (i) { + let replacedKey = i.replace(/{/, '').replace(/}/, ''); + if (!data[replacedKey]) { + return i; + } + return data[replacedKey]; + }); + } + } + return null; +} + +module.exports = stringFormat; \ No newline at end of file diff --git a/locale/en-US.json b/locale/en-US.json index 246316de..065309c0 100644 --- a/locale/en-US.json +++ b/locale/en-US.json @@ -26,7 +26,7 @@ "Copy Link": "Copy Link", "Cut": "Cut", "Inspect Element": "Inspect Element", - "Look Up ": "Look Up ", + "Look Up {searchText}": "Look Up \"{searchText}\"", "Open Link": "Open Link", "Paste": "Paste", "Reload": "Reload", diff --git a/locale/en.json b/locale/en.json index 4569b4a0..b139673e 100644 --- a/locale/en.json +++ b/locale/en.json @@ -26,7 +26,7 @@ "Copy Link": "Copy Link", "Cut": "Cut", "Inspect Element": "Inspect Element", - "Look Up ": "Look Up ", + "Look Up {searchText}": "Look Up \"{searchText}\"", "Open Link": "Open Link", "Paste": "Paste", "Reload": "Reload", diff --git a/locale/ja-JP.json b/locale/ja-JP.json index 00f4e57a..0918ee74 100644 --- a/locale/ja-JP.json +++ b/locale/ja-JP.json @@ -20,16 +20,16 @@ "ContextMenu": { "Add to Dictionary": "辞書に追加", "Copy": "コピー", - "Copy Email Address": "メールアドレスをコピーする", - "Copy Image": "イメージをコピーする", - "Copy Image URL": "コピー画像のURL", - "Copy Link": "リンクをコピーする", - "Cut": "カット", - "Inspect Element": "要素の検査", - "Look Up ": "見上げる", + "Copy Email Address": "電子メールアドレスをコピー", + "Copy Image": "画像をコピー", + "Copy Image URL": "画像のURLをコピー", + "Copy Link": "リンクをコピー", + "Cut": "切り取り", + "Inspect Element": "要素を調査", + "Look Up {searchText}": "「{searchText}」を検索", "Open Link": "リンクを開く", - "Paste": "ペースト", - "Reload": "リロード", + "Paste": "貼り付け", + "Reload": "再読み込み", "Search with Google": "Googleで検索" }, "DownloadManager": { diff --git a/locale/ja.json b/locale/ja.json index cf69c676..412280b1 100644 --- a/locale/ja.json +++ b/locale/ja.json @@ -20,16 +20,16 @@ "ContextMenu": { "Add to Dictionary": "辞書に追加", "Copy": "コピー", - "Copy Email Address": "メールアドレスをコピーする", - "Copy Image": "イメージをコピーする", - "Copy Image URL": "コピー画像のURL", - "Copy Link": "リンクをコピーする", - "Cut": "カット", - "Inspect Element": "要素の検査", - "Look Up ": "見上げる", + "Copy Email Address": "電子メールアドレスをコピー", + "Copy Image": "画像をコピー", + "Copy Image URL": "画像のURLをコピー", + "Copy Link": "リンクをコピー", + "Cut": "切り取り", + "Inspect Element": "要素を調査", + "Look Up {searchText}": "「{searchText}」を検索", "Open Link": "リンクを開く", - "Paste": "ペースト", - "Reload": "リロード", + "Paste": "貼り付け", + "Reload": "再読み込み", "Search with Google": "Googleで検索" }, "DownloadManager": {