From f18305776167a3838245fd7d42180ba67218bc46 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 14 Apr 2023 16:05:09 +0200 Subject: pogen: fix quoting of double quotes --- packages/pogen/bin/pogen | 2 +- packages/pogen/example/messages.po | 107 -------------------- packages/pogen/example/proj1/package.json | 5 +- packages/pogen/example/proj1/src/i18n/test.pot | 130 +++++++++++++++++++++++++ packages/pogen/example/proj1/src/test.ts | 67 +++++++++++++ packages/pogen/example/proj1/src/test2.tsx | 17 ++++ packages/pogen/example/test.ts | 64 ------------ packages/pogen/example/test2.tsx | 15 --- packages/pogen/src/potextract.ts | 4 +- 9 files changed, 222 insertions(+), 189 deletions(-) delete mode 100644 packages/pogen/example/messages.po create mode 100644 packages/pogen/example/proj1/src/i18n/test.pot create mode 100644 packages/pogen/example/proj1/src/test.ts create mode 100644 packages/pogen/example/proj1/src/test2.tsx delete mode 100644 packages/pogen/example/test.ts delete mode 100644 packages/pogen/example/test2.tsx (limited to 'packages/pogen') diff --git a/packages/pogen/bin/pogen b/packages/pogen/bin/pogen index a7ef879d8..3b17d1df7 100755 --- a/packages/pogen/bin/pogen +++ b/packages/pogen/bin/pogen @@ -1,2 +1,2 @@ -#!/usr/bin/env node +#!/usr/bin/env -S node --trace-deprecation require('../lib/pogen.js').main(); diff --git a/packages/pogen/example/messages.po b/packages/pogen/example/messages.po deleted file mode 100644 index 1addae3f2..000000000 --- a/packages/pogen/example/messages.po +++ /dev/null @@ -1,107 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-01-27 01:51+0100\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#: example/test.ts:3 -#, csharp-format -msgid "Hello1, World" -msgstr "" - -#: example/test.ts:4 -#, csharp-format -msgid "Hello2, World" -msgstr "" - -#: example/test.ts:5 -#, csharp-format -msgid "Hello3, World" -msgstr "" - -#. This is a comment and should be included -#: example/test.ts:9 -#, csharp-format -msgid "Hello4, World" -msgstr "" - -#: example/test.ts:12 -#, csharp-format -msgid "Hello5, World" -msgstr "" - -#: example/test.ts:13 -#, csharp-format -msgid "Hello6,{0} World" -msgstr "" - -#. This one has a multi line comment. -#. It has multiple lines, and a trailing empty line. -#. -#: example/test.ts:20 -#, csharp-format -msgid "Hello7,{0} World{1}" -msgstr "" - -#: example/test.ts:21 -#, csharp-format -msgid "{0}Hello8,{1} World{2}" -msgstr "" - -#. -#. This one has a multi line comment. -#. It has multiple lines, and a leading empty line. -#: example/test.ts:28 -#, csharp-format -msgid "Hello9,\" '\" World" -msgstr "" - -#: example/test.ts:32 -#, csharp-format -msgid "" -"Hello10\n" -" ,\" '\" Wo\n" -" rld" -msgstr "" - -#: example/test.ts:37 -#, csharp-format -msgid "" -"Hello11 this is a long long string\n" -"it will go over multiple lines and in the pofile\n" -"it should be wrapped and stuff" -msgstr "" - -#. This is a single line comment -#: example/test.ts:42 -#, csharp-format -msgid "" -"Hello12 this is a long long string it will go over multiple lines and in the " -"pofile it should be wrapped and stuff. asdf asdf asdf asdf asdf asdf asdf asdf " -"adsf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf " -"asdf" -msgstr "" - -#: example/test.ts:42 -#, csharp-format -msgid "This message appears twice" -msgstr "" - -#: example/test.ts:45 -#, csharp-format -msgid "This message appears twice" -msgstr "" - diff --git a/packages/pogen/example/proj1/package.json b/packages/pogen/example/proj1/package.json index 954139ecf..97adf0f3a 100644 --- a/packages/pogen/example/proj1/package.json +++ b/packages/pogen/example/proj1/package.json @@ -7,5 +7,8 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", - "license": "ISC" + "license": "ISC", + "pogen": { + "domain": "test" + } } diff --git a/packages/pogen/example/proj1/src/i18n/test.pot b/packages/pogen/example/proj1/src/i18n/test.pot new file mode 100644 index 000000000..8bc5ef236 --- /dev/null +++ b/packages/pogen/example/proj1/src/i18n/test.pot @@ -0,0 +1,130 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-11-23 00:00+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/test.ts:4 +#, c-format +msgid "Hello1, World" +msgstr "" + +#: src/test.ts:8 +#, c-format +msgid "Hello, quoted \"world\"" +msgstr "" + +#: src/test.ts:15 +#, c-format +msgid "Hello5, World" +msgstr "" + +#: src/test.ts:16 +#, c-format +msgid "Hello6,%1$s World" +msgstr "" + +#. This one has a multi line comment. +#. It has multiple lines, and a trailing empty line. +#. +#: src/test.ts:23 +#, c-format +msgid "Hello7,%1$s World%2$s" +msgstr "" + +#: src/test.ts:23 +#, c-format +msgid "one %1$s" +msgid_plural "many %1$s" +msgstr[0] "" +msgstr[1] "" + +#: src/test.ts:26 +#, c-format +msgid "one bla %1$s" +msgid_plural "many bla %1$s" +msgstr[0] "" +msgstr[1] "" + +#: src/test.ts:31 +#, c-format +msgid "I have %1$s apple" +msgid_plural "I have %1$s apples" +msgstr[0] "" +msgstr[1] "" + +#: src/test.ts:35 +#, c-format +msgid "%1$sHello8,%2$s World%3$s" +msgstr "" + +#. +#. This one has a multi line comment. +#. It has multiple lines, and a leading empty line. +#: src/test.ts:42 +#, c-format +msgid "Hello9,\" '\" World" +msgstr "" + +#: src/test.ts:46 +#, c-format +msgid "" +"Hello10\n" +" ,\" '\" Wo\n" +" rld" +msgstr "" + +#: src/test.ts:51 +#, c-format +msgid "" +"Hello11 this is a long long string\n" +"it will go over multiple lines and in the pofile\n" +"it should be wrapped and stuff" +msgstr "" + +#. This is a single line comment +#: src/test.ts:56 +#, c-format +msgid "" +"Hello12 this is a long long string it will go over multiple lines and in the " +"pofile it should be wrapped and stuff. asdf asdf asdf asdf asdf asdf asdf asdf " +"adsf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf " +"asdf" +msgstr "" + +#. First occurrence +#: src/test.ts:65 +#, c-format +msgid "This message appears twice" +msgstr "" + +#: src/test2.tsx:1 +#, c-format +msgid "foo %1$s foo baz" +msgstr "" + +#: src/test2.tsx:5 +#, c-format +msgid "singular form second line" +msgid_plural "plural form" +msgstr[0] "" +msgstr[1] "" + +#: src/test2.tsx:17 +#, c-format +msgid "\"foo\"" +msgstr "" + diff --git a/packages/pogen/example/proj1/src/test.ts b/packages/pogen/example/proj1/src/test.ts new file mode 100644 index 000000000..2e9b4cbdd --- /dev/null +++ b/packages/pogen/example/proj1/src/test.ts @@ -0,0 +1,67 @@ +declare var i18n: any; + + +console.log(i18n`Hello1, World`); +console.log(i18n.foo()`Hello2, World`); +console.log(i18n.foo()`Hello3, World`); + +console.log(i18n`Hello, quoted "world"`); + + +/* This is a comment and should be included */ +console.log(i18n().foo()`Hello4, World`); + + +console.log(i18n.foo`Hello5, World`); +console.log(i18n.foo`Hello6,${123} World`); + +/* +This one has a multi line comment. +It has multiple lines, and a trailing empty line. + +*/ +console.log(/*lol*/i18n.foo`Hello7,${123} World${42}`); + +// @ts-expect-error +i18n.plural(i18n`one ${"foo"}`, i18`many ${"bar"}`); + +// @ts-expect-error +i18n.plural(i18n.foo`one bla ${"foo"}`, i18.foo`many bla ${"bar"}`); + +let x = 42; + +i18n.plural(i18n`I have ${x} apple`, i18n`I have ${x} apples`); + +console.log(i18n`${"foo"}Hello8,${123} World${42}`); + +/* + +This one has a multi line comment. +It has multiple lines, and a leading empty line. +*/ +console.log(i18n`Hello9," '" World`); + +// Comments with space in between do not count + +console.log(i18n`Hello10 + ," '" Wo + rld`); + + +console.log(i18n`Hello11 this is a long long string +it will go over multiple lines and in the pofile +it should be wrapped and stuff`); + +// This is a single line comment +console.log(i18n`Hello12 this is a long long string it will go over multiple lines and in the pofile it should be wrapped and stuff. asdf asdf asdf asdf asdf asdf asdf asdf adsf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf`); + +function foo(...args: any[]) { +} + +console.log(foo`Another string, must be excluded`); + + +// First occurrence +console.log(i18n`This message appears twice`); +// Second occurrence +console.log(i18n`This message appears twice`); diff --git a/packages/pogen/example/proj1/src/test2.tsx b/packages/pogen/example/proj1/src/test2.tsx new file mode 100644 index 000000000..1c1ab49f2 --- /dev/null +++ b/packages/pogen/example/proj1/src/test2.tsx @@ -0,0 +1,17 @@ +let x = foo +{bar} {" foo "} baz + + +let y = ( + + + singular form + second line + + + plural form + + +); + +let z = "foo"; diff --git a/packages/pogen/example/test.ts b/packages/pogen/example/test.ts deleted file mode 100644 index 6577fa314..000000000 --- a/packages/pogen/example/test.ts +++ /dev/null @@ -1,64 +0,0 @@ -declare var i18n: any; - -console.log(i18n`Hello1, World`); -console.log(i18n.foo()`Hello2, World`); -console.log(i18n.foo()`Hello3, World`); - - -/* This is a comment and should be included */ -console.log(i18n().foo()`Hello4, World`); - - -console.log(i18n.foo`Hello5, World`); -console.log(i18n.foo`Hello6,${123} World`); - -/* -This one has a multi line comment. -It has multiple lines, and a trailing empty line. - -*/ -console.log(/*lol*/i18n.foo`Hello7,${123} World${42}`); - -// @ts-expect-error -i18n.plural(i18n`one ${"foo"}`, i18`many ${"bar"}`); - -// @ts-expect-error -i18n.plural(i18n.foo`one bla ${"foo"}`, i18.foo`many bla ${"bar"}`); - -let x = 42; - -i18n.plural(i18n`I have ${x} apple`, i18n`I have ${x} apples`); - -console.log(i18n`${"foo"}Hello8,${123} World${42}`); - -/* - -This one has a multi line comment. -It has multiple lines, and a leading empty line. -*/ -console.log(i18n`Hello9," '" World`); - -// Comments with space in between do not count - -console.log(i18n`Hello10 - ," '" Wo - rld`); - - -console.log(i18n`Hello11 this is a long long string -it will go over multiple lines and in the pofile -it should be wrapped and stuff`); - -// This is a single line comment -console.log(i18n`Hello12 this is a long long string it will go over multiple lines and in the pofile it should be wrapped and stuff. asdf asdf asdf asdf asdf asdf asdf asdf adsf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf`); - -function foo(...args: any[]) { -} - -console.log(foo`Another string, must be excluded`); - - -// First occurrence -console.log(i18n`This message appears twice`); -// Second occurrence -console.log(i18n`This message appears twice`); diff --git a/packages/pogen/example/test2.tsx b/packages/pogen/example/test2.tsx deleted file mode 100644 index 4133f86fb..000000000 --- a/packages/pogen/example/test2.tsx +++ /dev/null @@ -1,15 +0,0 @@ -let x = foo -{bar} {" foo "} baz - - -let y = ( - - - singular form - second line - - - plural form - - -); diff --git a/packages/pogen/src/potextract.ts b/packages/pogen/src/potextract.ts index e75c17d55..3e9a95ded 100644 --- a/packages/pogen/src/potextract.ts +++ b/packages/pogen/src/potextract.ts @@ -154,7 +154,7 @@ function processFile( path, line: lc.line, comment: getComment(tte), - template: getTemplate(tte.template).replace(/"/g, '\\"'), + template: getTemplate(tte.template), }; return res; } @@ -172,6 +172,8 @@ function processFile( function formatMsgLine(head: string, msg: string) { // Do escaping, wrap break at newlines + console.log("head", JSON.stringify(head)); + console.log("msg", JSON.stringify(msg)); let parts = msg .match(/(.*\n|.+$)/g) .map((x) => x.replace(/\n/g, "\\n").replace(/"/g, '\\"')) -- cgit v1.2.3