diff options
Diffstat (limited to 'packages/pogen/src/potextract.test.ts')
-rw-r--r-- | packages/pogen/src/potextract.test.ts | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/packages/pogen/src/potextract.test.ts b/packages/pogen/src/potextract.test.ts new file mode 100644 index 000000000..d8f8cf6b6 --- /dev/null +++ b/packages/pogen/src/potextract.test.ts @@ -0,0 +1,104 @@ +/* + This file is part of GNU Taler + (C) 2022 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import test from "ava"; +import * as ts from "typescript"; +import { processFile2 } from "./potextract.js"; + +function wrapIntoFunction(src: string): string { + return ` +function testing():VNode { +return ${src} +} +`; +} + +function process(src: string): string { + const source = ts.createSourceFile( + "test.tsx", + wrapIntoFunction(src), + ts.ScriptTarget.ES2020, + ); + return processFile2(source).trim(); +} + +test("should extract the key from inner body", (t) => { + t.deepEqual( + process(`<i18n.Translate>something</i18n.Translate>`), + `#: test.tsx:3 +#, c-format +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 ""`, + ); +}); |