From e95bd1ffc820288ffbb5f93cf221abcb31a992cc Mon Sep 17 00:00:00 2001 From: Tim Jackson Date: Mon, 9 Feb 2026 20:30:41 +1300 Subject: [PATCH] Add English (UK) locale option --- background/background.js | 12 +++++++++--- content_scripts/dictionary.js | 8 +++++++- options/options.html | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/background/background.js b/background/background.js index 5db7baa..4a5ec94 100644 --- a/background/background.js +++ b/background/background.js @@ -4,9 +4,15 @@ const GOOGLE_SPEECH_URI = 'https://www.google.com/speech-api/v1/synthesize', enabled: true }; +function getRegionForLanguage(lang) { + if (lang === 'en-GB') { return 'GB'; } + return 'US'; +} + browser.runtime.onMessage.addListener((request, sender, sendResponse) => { - const { word, lang } = request, - url = `https://www.google.com/search?hl=${lang}&q=define+${word}&gl=US`; + const { word, lang } = request, + region = getRegionForLanguage(lang), + url = `https://www.google.com/search?hl=${lang}&q=define+${word}&gl=${region}`; fetch(url, { method: 'GET' @@ -83,4 +89,4 @@ function saveWord (content) { definitions }); }) -} \ No newline at end of file +} diff --git a/content_scripts/dictionary.js b/content_scripts/dictionary.js index fbb2595..b8c8dab 100644 --- a/content_scripts/dictionary.js +++ b/content_scripts/dictionary.js @@ -21,6 +21,11 @@ createdDiv = createDiv(info); } + function getRegionForLanguage(lang) { + if (lang === 'en-GB') { return 'GB'; } + return 'US'; + } + function getSelectionInfo(event) { var word; @@ -108,7 +113,8 @@ audio.style.display = "none"; var moreInfo =document.createElement("a"); - moreInfo.href = `https://www.google.com/search?hl=${LANGUAGE}&q=define+${info.word}`; + var region = getRegionForLanguage(LANGUAGE); + moreInfo.href = `https://www.google.com/search?hl=${LANGUAGE}&q=define+${info.word}&gl=${region}`; moreInfo.style = "float: right; text-decoration: none;" moreInfo.target = "_blank"; diff --git a/options/options.html b/options/options.html index d1ff023..e466a1c 100644 --- a/options/options.html +++ b/options/options.html @@ -17,6 +17,7 @@