Bug 1455649 - DocumentL10n, part 5 - Add directionality setting to DOMLocalization::translateRoots.
MozReview-Commit-ID: JQcfMCb1SQM
--- 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
// &, &, &.
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
*/