commit 1ba59463b15738634d2fc38cbfb9d1f519ce124d
parent 80f72573e346d9651bc02d9f14ff26f0d3434359
Author: Sebastian <sebasjm@gmail.com>
Date: Mon, 24 Nov 2025 11:53:52 -0300
report missing ids
Diffstat:
1 file changed, 39 insertions(+), 15 deletions(-)
diff --git a/packages/pogen/src/potextract.ts b/packages/pogen/src/potextract.ts
@@ -443,9 +443,15 @@ function processNode(
switch (node.kind) {
case ts.SyntaxKind.JsxElement:
let path = getJsxElementPath(node);
+ // <i18n.Translate>text</i18n.Translate>
if (arrayEq(path, ["i18n", "Translate"])) {
const content = getJsxContent(node);
const { line } = ts.getLineAndCharacterOfPosition(sourceFile, node.pos);
+ if (!content) {
+ throw Error(
+ `string to be translated can't be empty: ${sourceFile.fileName}:${line}`,
+ );
+ }
const comment = getComment(
sourceFile,
preLastTokLine,
@@ -467,27 +473,34 @@ function processNode(
return;
}
if (arrayEq(path, ["i18n", "TranslateSwitch"])) {
- let { line } = ts.getLineAndCharacterOfPosition(sourceFile, node.pos);
- let comment = getComment(sourceFile, preLastTokLine, lastTokLine, node);
+ const { line } = ts.getLineAndCharacterOfPosition(sourceFile, node.pos);
+ const comment = getComment(
+ sourceFile,
+ preLastTokLine,
+ lastTokLine,
+ node,
+ );
formatMsgComment(projectPrefix, sourceFile, outChunks, line, comment);
- let singularForm = getJsxSingular(node);
- if (!singularForm) {
- console.error("singular form missing");
- process.exit(1);
+ const content = getJsxSingular(node);
+ if (!content) {
+ throw Error(
+ `string to be translated can't be empty, singular is missing: ${sourceFile.fileName}:${line}`,
+ );
}
- let pluralForm = getJsxPlural(node);
+ const pluralForm = getJsxPlural(node);
if (!pluralForm) {
- console.error("plural form missing");
- process.exit(1);
+ throw Error(
+ `string to be translated can't be empty, plural is missing: ${sourceFile.fileName}:${line}`,
+ );
}
const context = getJsxAttribute(sourceFile, node)["context"] ?? "";
- const msgid = context + singularForm;
+ const msgid = context + content;
if (!knownMessageIds.has(msgid)) {
knownMessageIds.add(msgid);
const screenId = searchScreenId(parents, sourceFile);
formatScreenId(sourceFile, outChunks, screenId);
formatMsgLine(outChunks, "msgctxt", context);
- formatMsgLine(outChunks, "msgid", singularForm);
+ formatMsgLine(outChunks, "msgid", content);
formatMsgLine(outChunks, "msgid_plural", pluralForm);
outChunks.push(`msgstr[0] ""\n`);
outChunks.push(`msgstr[1] ""\n`);
@@ -516,12 +529,18 @@ function processNode(
preLastTokLine = lastTokLine; // HERE
lastTokLine = lc1.line;
}
- let t1 = processTaggedTemplateExpression(
+ const t1 = processTaggedTemplateExpression(
sourceFile,
preLastTokLine,
lastTokLine,
tte1,
);
+ const content = t1.template;
+ if (!content) {
+ throw Error(
+ `string to be translated can't be empty: ${sourceFile.fileName}:${line}`,
+ );
+ }
const tte2 = <ts.TaggedTemplateExpression>ce.arguments[1];
let lc2 = ts.getLineAndCharacterOfPosition(sourceFile, tte2.pos);
@@ -536,14 +555,14 @@ function processNode(
tte2,
);
let comment = getComment(sourceFile, preLastTokLine, lastTokLine, ce);
- const msgid = path.ctx + t1.template;
+ const msgid = path.ctx + content;
if (!knownMessageIds.has(msgid)) {
knownMessageIds.add(msgid);
const screenId = searchScreenId(parents, sourceFile);
formatScreenId(sourceFile, outChunks, screenId);
formatMsgComment(projectPrefix, sourceFile, outChunks, line, comment);
formatMsgLine(outChunks, "msgctxt", path.ctx);
- formatMsgLine(outChunks, "msgid", t1.template);
+ formatMsgLine(outChunks, "msgid", content);
formatMsgLine(outChunks, "msgid_plural", t2.template);
outChunks.push(`msgstr[0] ""\n`);
outChunks.push(`msgstr[1] ""\n`);
@@ -560,7 +579,7 @@ function processNode(
preLastTokLine = lastTokLine;
lastTokLine = lc2.line;
}
- let { comment, template, line, path, context } =
+ const { comment, template, line, path, context } =
processTaggedTemplateExpression(
sourceFile,
preLastTokLine,
@@ -570,6 +589,11 @@ function processNode(
if (path[0] != "i18n") {
break;
}
+ if (!template) {
+ throw Error(
+ `string to be translated can't be empty: ${sourceFile.fileName}:${line}`,
+ );
+ }
const msgid = context + template;
if (!knownMessageIds.has(msgid)) {
knownMessageIds.add(msgid);