Bug 1410733 - Add an en-US locale as a hard fallback for LocaleService::RequestedLocales. r?jfkthame
MozReview-Commit-ID: LPS3PaeykEh
--- 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);