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) {
setGlobalNotification({
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",
to,
});

View File

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

View File

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

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\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"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,68 +17,78 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: example/test.ts:3
#, csharp-format
#: src/test.ts:4
#, c-format
msgid "Hello1, World"
msgstr ""
#: example/test.ts:4
#, csharp-format
msgid "Hello2, World"
#: src/test.ts:8
#, c-format
msgid "Hello, quoted \"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
#: src/test.ts:15
#, c-format
msgid "Hello5, World"
msgstr ""
#: example/test.ts:13
#, csharp-format
msgid "Hello6,{0} World"
#: 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.
#.
#: example/test.ts:20
#, csharp-format
msgid "Hello7,{0} World{1}"
#: src/test.ts:23
#, c-format
msgid "Hello7,%1$s World%2$s"
msgstr ""
#: example/test.ts:21
#, csharp-format
msgid "{0}Hello8,{1} World{2}"
#: 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.
#: example/test.ts:28
#, csharp-format
#: src/test.ts:42
#, c-format
msgid "Hello9,\" '\" World"
msgstr ""
#: example/test.ts:32
#, csharp-format
#: src/test.ts:46
#, c-format
msgid ""
"Hello10\n"
" ,\" '\" Wo\n"
" rld"
msgstr ""
#: example/test.ts:37
#, csharp-format
#: 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"
@ -86,8 +96,8 @@ msgid ""
msgstr ""
#. This is a single line comment
#: example/test.ts:42
#, csharp-format
#: 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 "
@ -95,13 +105,26 @@ msgid ""
"asdf"
msgstr ""
#: example/test.ts:42
#, csharp-format
#. First occurrence
#: src/test.ts:65
#, c-format
msgid "This message appears twice"
msgstr ""
#: example/test.ts:45
#, csharp-format
msgid "This message appears twice"
#: 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 ""

View File

@ -1,9 +1,12 @@
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`);

View File

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

View File

@ -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, '\\"'))