diff options
author | Sebastian <sebasjm@gmail.com> | 2024-10-29 12:52:28 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-10-29 12:54:17 -0300 |
commit | 590073c50f2561ee10538fe0cfda5378a501bbd7 (patch) | |
tree | c38393160df6b7d5e6473be6339d5180df725ca7 /packages/pogen/src/potextract.test.ts | |
parent | f6ca179d6da99b61988529cbd91a6177d6f3e692 (diff) |
add support for context
Diffstat (limited to 'packages/pogen/src/potextract.test.ts')
-rw-r--r-- | packages/pogen/src/potextract.test.ts | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/packages/pogen/src/potextract.test.ts b/packages/pogen/src/potextract.test.ts index 32dfa5dfb..d8f8cf6b6 100644 --- a/packages/pogen/src/potextract.test.ts +++ b/packages/pogen/src/potextract.test.ts @@ -35,7 +35,7 @@ function process(src: string): string { return processFile2(source).trim(); } -test("p2p: should select the coin", (t) => { +test("should extract the key from inner body", (t) => { t.deepEqual( process(`<i18n.Translate>something</i18n.Translate>`), `#: test.tsx:3 @@ -44,3 +44,61 @@ msgid "something" msgstr ""`, ); }); + +test("should support context on tags", (t) => { + t.deepEqual( + process( + `return <div> + <i18n.Translate context="some_context" anotherkey="not the context" asd={"asd"} zxc={asd()}>something</i18n.Translate> + </div>`, + ), + `#: test.tsx:4 +#, c-format +msgctxt "some_context" +msgid "something" +msgstr ""`, + ); +}); + +test("should support context on string template", (t) => { + t.deepEqual( + process(`return i18n.context("wire transfer")\`send\`;`), + `#: test.tsx:3 +#, c-format +msgctxt "wire transfer" +msgid "send" +msgstr ""`, + ); +}); + +test("should support same message id with different context", (t) => { + t.deepEqual( + process( + `return i18n.context("wire transfer")\`send\` + i18n.context("gift")\`send\`;`, + ), + `#: test.tsx:3 +#, c-format +msgctxt "wire transfer" +msgid "send" +msgstr "" + +#: test.tsx:3 +#, c-format +msgctxt "gift" +msgid "send" +msgstr ""`, + ); +}); + +test("should support on string template", (t) => { + t.deepEqual( + process(` + // comment of the translation + return i18n.str\`another key\`;`), + `#. comment of the translation +#: test.tsx:5 +#, c-format +msgid "another key" +msgstr ""`, + ); +}); |