1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Testing DOMLocalization in XUL environment">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
<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>
|