Bug 1423463 - Update the LocaleService to handle ja-JP-mac better. r=jfkthame

MozReview-Commit-ID: 9LzDgbIHnhW

--HG--
extra : rebase_source : d007274d6fed77ddb0b53765bb0f2a3abc689185
This commit is contained in:
Zibi Braniecki 2017-12-07 11:51:31 -08:00
parent e9ad31bdf1
commit 013a1dfb6b

View File

@ -81,14 +81,12 @@ ReadRequestedLocales(nsTArray<nsCString>& aRetVal)
if (str.Length() > 0) { if (str.Length() > 0) {
for (const nsACString& part : str.Split(',')) { for (const nsACString& part : str.Split(',')) {
nsAutoCString locale(part); nsAutoCString locale(part);
if (SanitizeForBCP47(locale, true)) { if (locale.EqualsLiteral("ja-JP-mac")) {
// This is a hack required for us to handle the special Mozilla `ja-JP-mac` // This is a hack required to handle the special Mozilla `ja-JP-mac` locale.
// locales. We sanitize the input to normalize the case etc. but in result if (!aRetVal.Contains(locale)) {
// the `ja-JP-mac` will get turned into a BCP47 tag. Here we're turning it aRetVal.AppendElement(locale);
// back into the form expected by Gecko resources.
if (locale.EqualsLiteral("ja-JP-x-lvariant-mac")) {
locale.Assign("ja-JP-mac");
} }
} else if (SanitizeForBCP47(locale, true)) {
if (!aRetVal.Contains(locale)) { if (!aRetVal.Contains(locale)) {
aRetVal.AppendElement(locale); aRetVal.AppendElement(locale);
} }
@ -837,7 +835,7 @@ LocaleService::Locale::Locale(const nsCString& aLocale, bool aRange)
} }
break; break;
case 3: case 3:
if (part.EqualsLiteral("*") || part.Length() == 3) { if (part.EqualsLiteral("*") || (part.Length() >= 3 && part.Length() <= 8)) {
mVariant.Assign(part); mVariant.Assign(part);
} }
break; break;
@ -992,14 +990,11 @@ LocaleService::SetRequestedLocales(const char** aRequested,
for (uint32_t i = 0; i < aRequestedCount; i++) { for (uint32_t i = 0; i < aRequestedCount; i++) {
nsAutoCString locale(aRequested[i]); nsAutoCString locale(aRequested[i]);
if (!SanitizeForBCP47(locale, true)) { if (!locale.EqualsLiteral("ja-JP-mac") &&
!SanitizeForBCP47(locale, true)) {
NS_ERROR("Invalid language tag provided to SetRequestedLocales!"); NS_ERROR("Invalid language tag provided to SetRequestedLocales!");
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
if (locale.EqualsLiteral("ja-JP-x-lvariant-mac")) {
// This is a hack for our code to handle `ja-JP-mac` special case.
locale.Assign("ja-JP-mac");
}
if (i > 0) { if (i > 0) {
str.AppendLiteral(","); str.AppendLiteral(",");