tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_translateRoots.html (1463B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test DOMLocalization.prototype.translateRoots</title>
      6  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
      8  <script type="application/javascript">
      9  "use strict";
     10  const l10nReg = new L10nRegistry();
     11  const fs = [
     12    { path: "/localization/en-US/mock.ftl", source: `
     13 title = Hello World
     14 title2 = Hello Another World
     15 ` },
     16  ];
     17  const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs);
     18  l10nReg.registerSources([source]);
     19 
     20  window.onload = async function() {
     21    SimpleTest.waitForExplicitFinish();
     22 
     23    const domLoc = new DOMLocalization(
     24      [],
     25      false,
     26      l10nReg,
     27      ["en-US"],
     28    );
     29 
     30    const frag1 = document.querySelectorAll("div")[0];
     31    const frag2 = document.querySelectorAll("div")[1];
     32    const h1 = document.querySelectorAll("h1")[0];
     33    const h2 = document.querySelectorAll("h2")[0];
     34 
     35    domLoc.addResourceIds(["/mock.ftl"]);
     36    domLoc.connectRoot(frag1);
     37    domLoc.connectRoot(frag2);
     38 
     39    await domLoc.translateRoots();
     40 
     41    is(h1.textContent, "Hello World");
     42    is(h2.textContent, "Hello Another World");
     43 
     44    SimpleTest.finish();
     45  };
     46  </script>
     47 </head>
     48 <body>
     49  <div>
     50    <h1 data-l10n-id="title"></h1>
     51  </div>
     52  <div>
     53    <h2 data-l10n-id="title2"></h2>
     54  </div>
     55 </body>
     56 </html>