test_translateFragment.html (1309B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test DOMLocalization.prototype.translateFragment</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 subtitle = Welcome to FluentBundle 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 ["/mock.ftl"], 25 false, 26 l10nReg, 27 ["en-US"], 28 ); 29 30 const frag = document.querySelectorAll("div")[0]; 31 const h1 = document.querySelectorAll("h1")[0]; 32 const p1 = document.querySelectorAll("p")[0]; 33 34 await domLoc.translateFragment(frag); 35 is(h1.textContent, "Hello World"); 36 is(p1.textContent, "Welcome to FluentBundle"); 37 38 SimpleTest.finish(); 39 }; 40 </script> 41 </head> 42 <body> 43 <div> 44 <h1 data-l10n-id="title" /> 45 <p data-l10n-id="subtitle" /> 46 </div> 47 </body> 48 </html>