Bug 1410733 - Add an en-US locale as a hard fallback for LocaleService::RequestedLocales. r?jfkthame draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Sun, 22 Oct 2017 11:00:09 -0700
changeset 685489 178099b55b79afd34c20f85776ed7160b58ba817
parent 684481 8ccbd32831c7c7e9a253aaa35834f1d7b7244672
child 685490 5b77cea9034aa564532a901c1b7cc8ccf19b87ed
push id85943
push userbmo:gandalf@aviary.pl
push dateTue, 24 Oct 2017 17:29:07 +0000
reviewersjfkthame
bugs1410733
milestone58.0a1
Bug 1410733 - Add an en-US locale as a hard fallback for LocaleService::RequestedLocales. r?jfkthame MozReview-Commit-ID: LPS3PaeykEh
intl/locale/LocaleService.cpp
--- a/intl/locale/LocaleService.cpp
+++ b/intl/locale/LocaleService.cpp
@@ -258,16 +258,26 @@ LocaleService::AssignRequestedLocales(co
   }
 }
 
 bool
 LocaleService::GetRequestedLocales(nsTArray<nsCString>& aRetVal)
 {
   if (mRequestedLocales.IsEmpty()) {
     ReadRequestedLocales(mRequestedLocales);
+
+    // en-US is a LastResort locale. LastResort locale is a fallback locale
+    // for the requested locale chain. In the future we'll want to make the
+    // fallback chain differ per-locale. For now, it'll always fallback on en-US.
+    //
+    // Notice: This is not the same as DefaultLocale,
+    // which follows the default locale the build is in.
+    if (!mRequestedLocales.Contains("en-US")) {
+      mRequestedLocales.AppendElement("en-US");
+    }
   }
 
   aRetVal = mRequestedLocales;
   return true;
 }
 
 bool
 LocaleService::GetAvailableLocales(nsTArray<nsCString>& aRetVal)
@@ -937,17 +947,19 @@ LocaleService::GetRequestedLocale(nsACSt
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 LocaleService::SetRequestedLocales(const char** aRequested,
                                    uint32_t aRequestedCount)
 {
-  MOZ_ASSERT(aRequestedCount < 2, "We can only handle one requested locale");
+  MOZ_ASSERT(aRequestedCount < 2 ||
+             (aRequestedCount == 2 && strcmp(aRequested[1], "en-US") == 0),
+      "We can only handle one requested locale (optionally with en-US last fallback)");
 
   if (aRequestedCount == 0) {
     Preferences::ClearUser(SELECTED_LOCALE_PREF);
   } else {
     Preferences::SetCString(SELECTED_LOCALE_PREF, aRequested[0]);
   }
 
   Preferences::SetBool(MATCH_OS_LOCALE_PREF, aRequestedCount == 0);