summaryrefslogtreecommitdiffstats
path: root/intl
diff options
context:
space:
mode:
authorMoonchild <mcwerewolf@gmail.com>2018-08-26 07:45:17 +0200
committerGitHub <noreply@github.com>2018-08-26 07:45:17 +0200
commit2dc1703c09b080b12e81895cafc1113e860cfe9a (patch)
tree98a0e285554ed33dafd3834261017c6b23fe3a17 /intl
parent4cbcba7876e1d85e9fadeb20a1ce34c58ffd7b93 (diff)
parent02211f8448876cd7c72784380b9e9229959392bb (diff)
downloadUXP-2dc1703c09b080b12e81895cafc1113e860cfe9a.tar
UXP-2dc1703c09b080b12e81895cafc1113e860cfe9a.tar.gz
UXP-2dc1703c09b080b12e81895cafc1113e860cfe9a.tar.lz
UXP-2dc1703c09b080b12e81895cafc1113e860cfe9a.tar.xz
UXP-2dc1703c09b080b12e81895cafc1113e860cfe9a.zip
Merge pull request #733 from JustOff/PR_locale_changed_refresh
Refresh nsStringBundleService and nsHttpHandler when the browser locale is changed
Diffstat (limited to 'intl')
-rw-r--r--intl/strres/nsStringBundle.cpp27
-rw-r--r--intl/strres/nsStringBundleService.h2
2 files changed, 29 insertions, 0 deletions
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))
{
@@ -560,6 +579,14 @@ nsStringBundleService::Observe(nsISupports* aSubject,
}
void
+nsStringBundleService::notifyBundlesFlushed()
+{
+ nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
+ NS_ASSERTION(obsSvc, "Couldn't get observer service.");
+ obsSvc->NotifyObservers(nullptr, "string-bundles-have-flushed", nullptr);
+}
+
+void
nsStringBundleService::flushBundleCache()
{
// release all bundles in the cache
diff --git a/intl/strres/nsStringBundleService.h b/intl/strres/nsStringBundleService.h
index a192cdff8..e65c61f12 100644
--- a/intl/strres/nsStringBundleService.h
+++ b/intl/strres/nsStringBundleService.h
@@ -43,6 +43,8 @@ private:
void flushBundleCache();
+ void notifyBundlesFlushed();
+
bundleCacheEntry_t *insertIntoCache(already_AddRefed<nsIStringBundle> aBundle,
nsCString &aHashKey);