Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
type="text/css"?>
title="Testing DOMLocalization in XUL environment">
<script type="application/javascript">
<![CDATA[
const l10nReg = new L10nRegistry();
const fs = [
{ path: "/localization/en-US/mock.ftl", source: `
file-menu =
.label = File
.accesskey = F
new-tab =
.label = New Tab
.accesskey = N
container = Some text with an <image data-l10n-name="foo"> inside it.
` },
];
const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs);
l10nReg.registerSources([source]);
SimpleTest.waitForExplicitFinish();
const domLoc = new DOMLocalization(
[],
false,
l10nReg,
["en-US"],
);
async function foo() {
domLoc.addResourceIds(["/mock.ftl"]);
domLoc.connectRoot(document.documentElement);
await domLoc.translateRoots();
is(document.getElementById('file-menu').getAttribute('label'), 'File');
is(document.getElementById('file-menu').getAttribute('accesskey'), 'F');
is(document.getElementById('new-tab').getAttribute('label'), 'New Tab');
is(document.getElementById('new-tab').getAttribute('accesskey'), 'N');
ok(document.querySelector("image"),
"Image should still be present after localization.");
SimpleTest.finish();
}
window.onload = foo;
]]>
</script>
<description data-l10n-id="container"><image data-l10n-name="foo"/></description>
<menubar id="main-menubar">
<menu id="file-menu" data-l10n-id="file-menu">
<menupopup id="menu_FilePopup">
<menuitem id="new-tab" data-l10n-id="new-tab">
</menuitem>
</menupopup>
</menu>
</menubar>
</window>