Bug 1480798 - Set document's directionality in Fluent. r=stas

Set document's directionality in Fluent.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Zibi Braniecki 2018-08-03 17:21:37 +00:00
Родитель a66914000b
Коммит 0abff42b51
1 изменённых файлов: 16 добавлений и 1 удалений

Просмотреть файл

@ -20,6 +20,8 @@
const { Localization } =
ChromeUtils.import("resource://gre/modules/Localization.jsm", {});
const { Services } =
ChromeUtils.import("resource://gre/modules/Services.jsm", {});
// Match the opening angle bracket (<) in HTML tags, and HTML entities like
// &amp;, &#0038;, &#x0026;.
@ -572,7 +574,20 @@ class DOMLocalization extends Localization {
translateRoots() {
const roots = Array.from(this.roots);
return Promise.all(
roots.map(root => this.translateFragment(root))
roots.map(async root => {
// We want to first retranslate the UI, and
// then (potentially) flip the directionality.
//
// This means that the DOM alternations and directionality
// are set in the same microtask.
await this.translateFragment(root);
let primaryLocale = Services.locale.getAppLocaleAsBCP47();
let direction = Services.locale.isAppLocaleRTL ? "rtl" : "ltr";
root.setAttribute("lang", primaryLocale);
root.setAttribute(root.namespaceURI ===
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
? "localedir" : "dir", direction);
})
);
}