Bug 1493625 - Make LocaleService::IsAppLocaleRTL react to pseudo. r=flod,jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D6689

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Zibi Braniecki 2018-09-25 16:48:16 +00:00
parent 3d0ca1234a
commit 70411b2b33
3 changed files with 43 additions and 3 deletions

View File

@ -656,6 +656,7 @@ select the strategy to be used:
This strategy replaces all Latin characters with their 180 degree rotated versions
and enforces right to left text flow using Unicode UAX#9 `Explicit Directional Embeddings`__.
In this mode, the UI directionality will also be set to right-to-left.
__ https://www.unicode.org/reports/tr9/#Explicit_Directional_Embeddings

View File

@ -416,13 +416,27 @@ LocaleService::FilterMatches(const nsTArray<nsCString>& aRequested,
bool
LocaleService::IsAppLocaleRTL()
{
nsAutoCString locale;
GetAppLocaleAsBCP47(locale);
// First, let's check if there's a manual override
// preference for directionality set.
int pref = Preferences::GetInt("intl.uidirection", -1);
if (pref >= 0) {
return (pref > 0);
}
// If not, check if there is a pseudo locale `bidi`
// set.
nsAutoCString locale;
if (NS_SUCCEEDED(Preferences::GetCString("intl.l10n.pseudo", locale))) {
if (locale.EqualsLiteral("bidi")) {
return true;
}
if (locale.EqualsLiteral("accented")) {
return false;
}
}
GetAppLocaleAsBCP47(locale);
return uloc_isRightToLeft(locale.get());
}

View File

@ -142,6 +142,31 @@ add_test(function test_isAppLocaleRTL() {
run_next_test();
});
add_test(function test_isAppLocaleRTL_pseudo() {
let avLocales = localeService.availableLocales;
let reqLocales = localeService.requestedLocales;
localeService.availableLocales = ["en-US"];
localeService.requestedLocales = ["en-US"];
Services.prefs.setIntPref("intl.uidirection", -1);
Services.prefs.setCharPref("intl.l10n.pseudo", "");
Assert.ok(localeService.isAppLocaleRTL === false);
Services.prefs.setCharPref("intl.l10n.pseudo", "bidi");
Assert.ok(localeService.isAppLocaleRTL === true);
Services.prefs.setCharPref("intl.l10n.pseudo", "accented");
Assert.ok(localeService.isAppLocaleRTL === false);
// Clean up
localeService.availableLocales = avLocales;
localeService.requestedLocales = reqLocales;
Services.prefs.clearUserPref("intl.l10n.pseudo");
run_next_test();
});
add_test(function test_packagedLocales() {
const locales = localeService.packagedLocales;
Assert.ok(locales.length !== 0, "Packaged locales are empty");