tor-browser

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

test_translateElements.html (1231B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test DOMLocalization.prototype.translateElements</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 link =
     15    .title = Click me
     16 ` },
     17  ];
     18  const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs);
     19  l10nReg.registerSources([source]);
     20 
     21  window.onload = async function() {
     22    SimpleTest.waitForExplicitFinish();
     23 
     24    const domLoc = new DOMLocalization(
     25      ["/mock.ftl"],
     26      false,
     27      l10nReg,
     28      ["en-US"],
     29    );
     30 
     31    const p1 = document.querySelectorAll("p")[0];
     32    const link1 = document.querySelectorAll("a")[0];
     33 
     34    await domLoc.translateElements([p1, link1]);
     35 
     36    is(p1.textContent, "Hello World");
     37    is(link1.getAttribute("title"), "Click me");
     38 
     39    SimpleTest.finish();
     40  };
     41  </script>
     42 </head>
     43 <body>
     44  <p data-l10n-id="title" />
     45  <a data-l10n-id="link" />
     46 </body>
     47 </html>