Bug 1480798 - Set document's directionality in Fluent. r=stas
☠☠ backed out by f20fddf6df08 ☠ ☠
authorZibi Braniecki <zbraniecki@mozilla.com>
Fri, 03 Aug 2018 17:21:37 +0000
changeset 430138 c0bf622859f64edad0f259277758bbbe11bb3cbf
parent 430137 4c130e2f5246501268180ec4399f8b5acc584e05
child 430139 09d7d2f8fe4f1176c93fc3028821a5aec1177430
push id34384
push userdvarga@mozilla.com
push dateSat, 04 Aug 2018 21:44:57 +0000
treeherdermozilla-central@073983e062f7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstas
bugs1480798
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1480798 - Set document's directionality in Fluent. r=stas Set document's directionality in Fluent. Differential Revision: https://phabricator.services.mozilla.com/D2732
intl/l10n/DOMLocalization.jsm
--- a/intl/l10n/DOMLocalization.jsm
+++ b/intl/l10n/DOMLocalization.jsm
@@ -15,16 +15,18 @@
  * limitations under the License.
  */
 
 
 /* fluent-dom@aa95b1f (July 10, 2018) */
 
 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;.
 const reOverlay = /<|&#?\w+;/;
 
 /**
  * Elements allowed in translations even if they are not present in the source
  * HTML. They are text-level elements as defined by the HTML5 spec:
@@ -567,17 +569,30 @@ class DOMLocalization extends Localizati
   /**
    * Translate all roots associated with this `DOMLocalization`.
    *
    * @returns {Promise}
    */
   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);
+      })
     );
   }
 
   /**
    * Pauses the `MutationObserver`.
    *
    * @private
    */