pogen: fix quoting of double quotes

This commit is contained in:
Florian Dold 2023-04-14 16:05:09 +02:00
parent 089c15582e
commit f183057761
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
8 changed files with 359 additions and 194 deletions

View File

@ -169,7 +169,7 @@ export function InstanceRoutes({
if (error.type === ErrorType.TIMEOUT) { if (error.type === ErrorType.TIMEOUT) {
setGlobalNotification({ setGlobalNotification({
message: i18n.str`The request to the backend take too long and was cancelled`, message: i18n.str`The request to the backend take too long and was cancelled`,
description: i18n.str`Diagnostic from ${error.info?.url} is '${error.message}'`, description: i18n.str`Diagnostic from ${error.info?.url} is "${error.message}"`,
type: "ERROR", type: "ERROR",
to, to,
}); });

View File

@ -1,2 +1,2 @@
#!/usr/bin/env node #!/usr/bin/env -S node --trace-deprecation
require('../lib/pogen.js').main(); require('../lib/pogen.js').main();

View File

@ -7,5 +7,8 @@
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "", "author": "",
"license": "ISC" "license": "ISC",
"pogen": {
"domain": "test"
}
} }

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-27 01:51+0100\n" "POT-Creation-Date: 2016-11-23 00:00+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,68 +17,78 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: example/test.ts:3 #: src/test.ts:4
#, csharp-format #, c-format
msgid "Hello1, World" msgid "Hello1, World"
msgstr "" msgstr ""
#: example/test.ts:4 #: src/test.ts:8
#, csharp-format #, c-format
msgid "Hello2, World" msgid "Hello, quoted \"world\""
msgstr "" msgstr ""
#: example/test.ts:5 #: src/test.ts:15
#, csharp-format #, c-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" msgid "Hello5, World"
msgstr "" msgstr ""
#: example/test.ts:13 #: src/test.ts:16
#, csharp-format #, c-format
msgid "Hello6,{0} World" msgid "Hello6,%1$s World"
msgstr "" msgstr ""
#. This one has a multi line comment. #. This one has a multi line comment.
#. It has multiple lines, and a trailing empty line. #. It has multiple lines, and a trailing empty line.
#. #.
#: example/test.ts:20 #: src/test.ts:23
#, csharp-format #, c-format
msgid "Hello7,{0} World{1}" msgid "Hello7,%1$s World%2$s"
msgstr "" msgstr ""
#: example/test.ts:21 #: src/test.ts:23
#, csharp-format #, c-format
msgid "{0}Hello8,{1} World{2}" 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 "" msgstr ""
#. #.
#. This one has a multi line comment. #. This one has a multi line comment.
#. It has multiple lines, and a leading empty line. #. It has multiple lines, and a leading empty line.
#: example/test.ts:28 #: src/test.ts:42
#, csharp-format #, c-format
msgid "Hello9,\" '\" World" msgid "Hello9,\" '\" World"
msgstr "" msgstr ""
#: example/test.ts:32 #: src/test.ts:46
#, csharp-format #, c-format
msgid "" msgid ""
"Hello10\n" "Hello10\n"
" ,\" '\" Wo\n" " ,\" '\" Wo\n"
" rld" " rld"
msgstr "" msgstr ""
#: example/test.ts:37 #: src/test.ts:51
#, csharp-format #, c-format
msgid "" msgid ""
"Hello11 this is a long long string\n" "Hello11 this is a long long string\n"
"it will go over multiple lines and in the pofile\n" "it will go over multiple lines and in the pofile\n"
@ -86,8 +96,8 @@ msgid ""
msgstr "" msgstr ""
#. This is a single line comment #. This is a single line comment
#: example/test.ts:42 #: src/test.ts:56
#, csharp-format #, c-format
msgid "" msgid ""
"Hello12 this is a long long string it will go over multiple lines and in the " "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 " "pofile it should be wrapped and stuff. asdf asdf asdf asdf asdf asdf asdf asdf "
@ -95,13 +105,26 @@ msgid ""
"asdf" "asdf"
msgstr "" msgstr ""
#: example/test.ts:42 #. First occurrence
#, csharp-format #: src/test.ts:65
#, c-format
msgid "This message appears twice" msgid "This message appears twice"
msgstr "" msgstr ""
#: example/test.ts:45 #: src/test2.tsx:1
#, csharp-format #, c-format
msgid "This message appears twice" 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 "" msgstr ""

View File

@ -1,9 +1,12 @@
declare var i18n: any; declare var i18n: any;
console.log(i18n`Hello1, World`); console.log(i18n`Hello1, World`);
console.log(i18n.foo()`Hello2, World`); console.log(i18n.foo()`Hello2, World`);
console.log(i18n.foo()`Hello3, World`); console.log(i18n.foo()`Hello3, World`);
console.log(i18n`Hello, quoted "world"`);
/* This is a comment and should be included */ /* This is a comment and should be included */
console.log(i18n().foo()`Hello4, World`); console.log(i18n().foo()`Hello4, World`);

View File

@ -13,3 +13,5 @@ let y = (
</i18n.TranslatePlural> </i18n.TranslatePlural>
</i18n.TranslateSwitch> </i18n.TranslateSwitch>
); );
let z = <i18n.Translate>"foo"</i18n.Translate>;

View File

@ -154,7 +154,7 @@ function processFile(
path, path,
line: lc.line, line: lc.line,
comment: getComment(tte), comment: getComment(tte),
template: getTemplate(tte.template).replace(/"/g, '\\"'), template: getTemplate(tte.template),
}; };
return res; return res;
} }
@ -172,6 +172,8 @@ function processFile(
function formatMsgLine(head: string, msg: string) { function formatMsgLine(head: string, msg: string) {
// Do escaping, wrap break at newlines // Do escaping, wrap break at newlines
console.log("head", JSON.stringify(head));
console.log("msg", JSON.stringify(msg));
let parts = msg let parts = msg
.match(/(.*\n|.+$)/g) .match(/(.*\n|.+$)/g)
.map((x) => x.replace(/\n/g, "\\n").replace(/"/g, '\\"')) .map((x) => x.replace(/\n/g, "\\n").replace(/"/g, '\\"'))