summaryrefslogtreecommitdiffstats
path: root/dom/l10n/tests/mochitest/dom_localization/test_translateRoots.html
blob: 58bfb044b0b1c9473875089b782df316848dc77d (plain)
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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test DOMLocalization.prototype.translateRoots</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  <script type="application/javascript">
  "use strict";
  const l10nReg = new L10nRegistry();
  const fs = [
    { path: "/localization/en-US/mock.ftl", source: `
title = Hello World
title2 = Hello Another World
` },
  ];
  const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs);
  l10nReg.registerSources([source]);

  window.onload = async function() {
    SimpleTest.waitForExplicitFinish();

    const domLoc = new DOMLocalization(
      [],
      false,
      l10nReg,
      ["en-US"],
    );

    const frag1 = document.querySelectorAll("div")[0];
    const frag2 = document.querySelectorAll("div")[1];
    const h1 = document.querySelectorAll("h1")[0];
    const h2 = document.querySelectorAll("h2")[0];

    domLoc.addResourceIds(["/mock.ftl"]);
    domLoc.connectRoot(frag1);
    domLoc.connectRoot(frag2);

    await domLoc.translateRoots();

    is(h1.textContent, "Hello World");
    is(h2.textContent, "Hello Another World");

    SimpleTest.finish();
  };
  </script>
</head>
<body>
  <div>
    <h1 data-l10n-id="title"></h1>
  </div>
  <div>
    <h2 data-l10n-id="title2"></h2>
  </div>
</body>
</html>