summaryrefslogtreecommitdiffstats
path: root/intl/strres/nsStringBundle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'intl/strres/nsStringBundle.cpp')
-rw-r--r--intl/strres/nsStringBundle.cpp27
1 files changed, 27 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