Bug 1455649 - DocumentL10n, part 5 - Add directionality setting to DOMLocalization::translateRoots. draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Mon, 25 Jun 2018 11:08:50 -0700
changeset 823654 4b5bac09e6edcb072a554aa345f38a836f054cb7
parent 823653 093d5a08199889856aeaf830a65b63cec7d77d8e
push id117750
push userbmo:gandalf@aviary.pl
push dateFri, 27 Jul 2018 18:29:20 +0000
bugs1455649
milestone63.0a1
Bug 1455649 - DocumentL10n, part 5 - Add directionality setting to DOMLocalization::translateRoots. MozReview-Commit-ID: JQcfMCb1SQM
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,24 @@ 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 => {
+        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
    */