Skip to content

Commit

Permalink
Reload the page when the preferredLanguage is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
agmmnn committed Oct 16, 2023
1 parent b62ffe3 commit fc8dd63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
})
}

Expand Down
7 changes: 7 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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')
Expand Down

0 comments on commit fc8dd63

Please sign in to comment.