From b31dec86baab720c6dff9dbfaac9dd4c12c8d67b Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 11 Jul 2017 18:03:35 +0300 Subject: [PATCH] reset L10N cache if our page is loaded before bg --- background.js | 8 +++----- localization.js | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/background.js b/background.js index 5adae9e8..a2ae0627 100644 --- a/background.js +++ b/background.js @@ -64,12 +64,10 @@ updateIcon({id: undefined}, {}); url: 'http://add0n.com/stylus.html' }); } - // reset L10N cache on UI language change or update - const {browserUIlanguage} = tryJSONparse(localStorage.L10N) || {}; - const UIlang = chrome.i18n.getUILanguage(); - if (reason == 'update' || browserUIlanguage != UIlang) { + // reset L10N cache on update + if (reason == 'update') { localStorage.L10N = JSON.stringify({ - browserUIlanguage: UIlang, + browserUIlanguage: chrome.i18n.getUILanguage(), }); } // TODO: remove in the future diff --git a/localization.js b/localization.js index 2a6ac4c4..0c5f578c 100644 --- a/localization.js +++ b/localization.js @@ -91,7 +91,16 @@ function tNodeList(nodes) { function tDocLoader() { t.cache = tryJSONparse(localStorage.L10N) || {}; + + // reset L10N cache on UI language change + const UIlang = chrome.i18n.getUILanguage(); + if (t.cache.browserUIlanguage != UIlang) { + t.cache = {browserUIlanguage: UIlang}; + localStorage.L10N = JSON.stringify(t.cache); + } + const cacheLength = Object.keys(t.cache).length; + // localize HEAD tNodeList(document.getElementsByTagName('*'));