@@ -5,7 +5,7 @@ import { vi } from "vitest";
55
66async function * mockGenerateMessages ( ) {
77 const bundle = new FluentBundle ( [ "en-US" ] ) ;
8- const resource = new FluentResource ( "key1 = Key 1" ) ;
8+ const resource = new FluentResource ( "key1 = Key 1\nkey2 = Key {$arg}\n " ) ;
99 bundle . addResource ( resource ) ;
1010 yield bundle ;
1111}
@@ -24,6 +24,24 @@ suite("translateFragment", function () {
2424 assert . strictEqual ( elem . textContent , "Key 1" ) ;
2525 } ) ;
2626
27+ test ( "translates a node with arguments" , async function ( ) {
28+ const FSI = "\u2068" ;
29+ const PDI = "\u2069" ;
30+ const domLoc = new DOMLocalization ( [ "test.ftl" ] , mockGenerateMessages ) ;
31+
32+ const frag = document . createDocumentFragment ( ) ;
33+ const elem = document . createElement ( "p" ) ;
34+ domLoc . setAttributes ( elem , "key2" , { arg : 42 } ) ;
35+ frag . appendChild ( elem ) ;
36+
37+ await domLoc . translateFragment ( frag ) ;
38+ assert . strictEqual ( elem . textContent , `Key ${ FSI } 42${ PDI } ` ) ;
39+
40+ domLoc . setArgs ( elem , { arg : 99 } ) ;
41+ await domLoc . translateFragment ( frag ) ;
42+ assert . strictEqual ( elem . textContent , `Key ${ FSI } 99${ PDI } ` ) ;
43+ } ) ;
44+
2745 test ( "does not inject content into a node with missing translation" , async function ( ) {
2846 const domLoc = new DOMLocalization ( [ "test.ftl" ] , mockGenerateMessages ) ;
2947
0 commit comments