From 02211f8448876cd7c72784380b9e9229959392bb Mon Sep 17 00:00:00 2001 From: JustOff Date: Sat, 25 Aug 2018 17:50:02 +0300 Subject: Refresh nsStringBundleService and nsHttpHandler when the browser locale is changed --- intl/strres/nsStringBundle.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'intl/strres/nsStringBundle.cpp') diff --git a/intl/strres/nsStringBundle.cpp b/intl/strres/nsStringBundle.cpp index ab840a469..717e368e2 100644 --- a/intl/strres/nsStringBundle.cpp +++ b/intl/strres/nsStringBundle.cpp @@ -25,6 +25,7 @@ #include "nsIErrorService.h" #include "nsICategoryManager.h" #include "nsContentUtils.h" +#include "mozilla/Preferences.h" // for async loading #ifdef ASYNC_LOADING @@ -32,6 +33,9 @@ #include "nsIStringStream.h" #endif +#define STR_HELPER(x) #x +#define STR(x) STR_HELPER(x) + using namespace mozilla; static NS_DEFINE_CID(kErrorServiceCID, NS_ERRORSERVICE_CID); @@ -529,6 +533,8 @@ nsStringBundleService::Init() os->AddObserver(this, "profile-do-change", true); os->AddObserver(this, "chrome-flush-caches", true); os->AddObserver(this, "xpcom-category-entry-added", true); + os->AddObserver(this, "selected-locale-has-changed", true); + os->AddObserver(this, "final-ui-startup", true); } // instantiate the override service, if there is any. @@ -550,6 +556,19 @@ nsStringBundleService::Observe(nsISupports* aSubject, { flushBundleCache(); } + else if (strcmp("selected-locale-has-changed", aTopic) == 0) + { + flushBundleCache(); + notifyBundlesFlushed(); + } + else if (strcmp("final-ui-startup", aTopic) == 0) + { + nsAdoptingCString ualocale = Preferences::GetCString("general.useragent.locale"); + if (!ualocale.EqualsLiteral(STR(MOZ_UI_LOCALE))) { + flushBundleCache(); + notifyBundlesFlushed(); + } + } else if (strcmp("xpcom-category-entry-added", aTopic) == 0 && NS_LITERAL_STRING("xpcom-autoregistration").Equals(aSomeData)) { @@ -559,6 +578,14 @@ nsStringBundleService::Observe(nsISupports* aSubject, return NS_OK; } +void +nsStringBundleService::notifyBundlesFlushed() +{ + nsCOMPtr obsSvc = mozilla::services::GetObserverService(); + NS_ASSERTION(obsSvc, "Couldn't get observer service."); + obsSvc->NotifyObservers(nullptr, "string-bundles-have-flushed", nullptr); +} + void nsStringBundleService::flushBundleCache() { -- cgit v1.2.3