mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
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:
parent
3d0ca1234a
commit
70411b2b33
@ -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
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user