From 48f9d75e2b3cdbf7c47e41cfe1a168fadbae5331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6k=C3=A7e?= Date: Mon, 16 Oct 2023 15:33:33 +0300 Subject: [PATCH] Reload the page when the `preferredLanguage` is changed (#70) --- src/options.ts | 5 +---- src/util.ts | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/options.ts b/src/options.ts index 48e3c00..0677dcc 100644 --- a/src/options.ts +++ b/src/options.ts @@ -65,10 +65,7 @@ window.addEventListener('DOMContentLoaded', async function () { languageSelect.addEventListener('change', function () { const selectedLanguage = this.value - chrome.storage.sync.set({ preferredLanguage: selectedLanguage }, function () { - // Reload the current page to apply the language change - location.reload() - }) + chrome.storage.sync.set({ preferredLanguage: selectedLanguage }) }) } diff --git a/src/util.ts b/src/util.ts index a56070e..f3482b2 100644 --- a/src/util.ts +++ b/src/util.ts @@ -156,6 +156,13 @@ export function createTranslationProxy(translationData: LangFile): TranslationPr // Function to localize HTML elements using translation data export function localizeElements(translationData: LangFile) { + chrome.storage.onChanged.addListener((changes, areaName) => { + if (areaName === 'sync' && 'preferredLanguage' in changes) { + // Reload the page when the preferredLanguage is changed + location.reload() + } + }) + document.querySelectorAll('[data-locale]').forEach((elem) => { const element = elem as HTMLElement const localeKey = element.getAttribute('data-locale')