[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] 09/15: add prefix
From: |
gnunet |
Subject: |
[taler-wallet-core] 09/15: add prefix |
Date: |
Wed, 04 Dec 2024 12:13:19 +0100 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
commit 6dbe349130e5c0a43c92423df962ea6d38cc9843
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Fri Nov 29 10:28:45 2024 -0300
add prefix
---
packages/pogen/src/potextract.test.ts | 4 ++--
packages/pogen/src/potextract.ts | 41 +++++++++++++++++++++++++----------
2 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/packages/pogen/src/potextract.test.ts
b/packages/pogen/src/potextract.test.ts
index 4cf7b71f1..d90698c2f 100644
--- a/packages/pogen/src/potextract.test.ts
+++ b/packages/pogen/src/potextract.test.ts
@@ -16,7 +16,7 @@
import test from "ava";
import * as ts from "typescript";
-import { processFile2 } from "./potextract.js";
+import { processFileForTesting } from "./potextract.js";
function wrapIntoFunction(src: string): string {
return `
@@ -33,7 +33,7 @@ function process(src: string): string {
wrapIntoFunction(src),
ts.ScriptTarget.ES2020,
);
- return processFile2(source).trim();
+ return processFileForTesting(source).trim();
}
test("should extract the key from inner body", (t) => {
diff --git a/packages/pogen/src/potextract.ts b/packages/pogen/src/potextract.ts
index b829fabfe..327b6da72 100644
--- a/packages/pogen/src/potextract.ts
+++ b/packages/pogen/src/potextract.ts
@@ -198,6 +198,7 @@ function formatScreenId(
}
function formatMsgComment(
+ projectPrefix: string,
sourceFile: ts.SourceFile,
outChunks: string[],
line: number,
@@ -208,7 +209,7 @@ function formatMsgComment(
outChunks.push(`#. ${cl}\n`);
}
}
- const fn = path.posix.relative(process.cwd(), sourceFile.fileName);
+ const fn = path.relative(projectPrefix, sourceFile.fileName);
outChunks.push(`#: ${fn}:${line + 1}\n`);
outChunks.push(`#, c-format\n`);
}
@@ -416,6 +417,7 @@ function processNode(
sourceFile: ts.SourceFile,
outChunks: string[],
knownMessageIds: Set<string>,
+ projectPrefix: string,
) {
switch (node.kind) {
case ts.SyntaxKind.JsxElement:
@@ -435,7 +437,7 @@ function processNode(
knownMessageIds.add(msgid);
const screenId = searchScreenId(parents, sourceFile);
formatScreenId(sourceFile, outChunks, screenId);
- formatMsgComment(sourceFile, outChunks, line, comment);
+ formatMsgComment(projectPrefix, sourceFile, outChunks, line,
comment);
formatMsgLine(outChunks, "msgctxt", context);
formatMsgLine(outChunks, "msgid", content);
outChunks.push(`msgstr ""\n`);
@@ -446,7 +448,7 @@ function processNode(
if (arrayEq(path, ["i18n", "TranslateSwitch"])) {
let { line } = ts.getLineAndCharacterOfPosition(sourceFile, node.pos);
let comment = getComment(sourceFile, preLastTokLine, lastTokLine,
node);
- formatMsgComment(sourceFile, outChunks, line, comment);
+ formatMsgComment(projectPrefix, sourceFile, outChunks, line, comment);
let singularForm = getJsxSingular(node);
if (!singularForm) {
console.error("singular form missing");
@@ -518,7 +520,7 @@ function processNode(
knownMessageIds.add(msgid);
const screenId = searchScreenId(parents, sourceFile);
formatScreenId(sourceFile, outChunks, screenId);
- formatMsgComment(sourceFile, outChunks, line, comment);
+ formatMsgComment(projectPrefix, sourceFile, outChunks, line, comment);
formatMsgLine(outChunks, "msgctxt", path.ctx);
formatMsgLine(outChunks, "msgid", t1.template);
formatMsgLine(outChunks, "msgid_plural", t2.template);
@@ -552,7 +554,7 @@ function processNode(
knownMessageIds.add(msgid);
const screenId = searchScreenId(parents, sourceFile);
formatScreenId(sourceFile, outChunks, screenId);
- formatMsgComment(sourceFile, outChunks, line, comment);
+ formatMsgComment(projectPrefix, sourceFile, outChunks, line, comment);
formatMsgLine(outChunks, "msgctxt", context);
formatMsgLine(outChunks, "msgid", template);
outChunks.push(`msgstr ""\n`);
@@ -571,15 +573,14 @@ function processNode(
sourceFile,
outChunks,
knownMessageIds,
+ projectPrefix
);
});
}
-export function processFile2(sourceFile: ts.SourceFile): string {
- // let lastTokLine = 0;
- // let preLastTokLine = 0;
+export function processFileForTesting(sourceFile: ts.SourceFile): string {
const result: string[] = new Array<string>();
- processNode([], sourceFile, 0, 0, sourceFile, result, new Set<string>());
+ processNode([], sourceFile, 0, 0, sourceFile, result, new Set<string>(), "");
return result.join("");
}
@@ -587,10 +588,25 @@ export function processFile(
sourceFile: ts.SourceFile,
outChunks: string[],
knownMessageIds: Set<string>,
+ projectPrefix: string,
) {
// let lastTokLine = 0;
// let preLastTokLine = 0;
- processNode([], sourceFile, 0, 0, sourceFile, outChunks, knownMessageIds);
+ processNode([], sourceFile, 0, 0, sourceFile, outChunks, knownMessageIds,
projectPrefix);
+}
+
+function searchIntoParents(directory: string, fileFlag: string) {
+ if (!path.isAbsolute(directory)) {
+ return searchIntoParents(path.join(process.cwd(), directory), fileFlag);
+ }
+ const parent = path.dirname(directory);
+ if (fs.existsSync(path.join(directory, fileFlag))) {
+ return directory;
+ }
+ if (parent === directory) {
+ return directory;
+ }
+ return searchIntoParents(parent, fileFlag);
}
export function potextract() {
@@ -637,12 +653,13 @@ export function potextract() {
header = DEFAULT_PO_HEADER;
}
- const chunks = [header];
+ const gitRoot = searchIntoParents(process.cwd(), ".git");
+ const chunks = [header];
const knownMessageIds = new Set<string>();
for (const f of ownFiles) {
- processFile(f, chunks, knownMessageIds);
+ processFile(f, chunks, knownMessageIds, gitRoot);
}
const pot = chunks.join("");
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-wallet-core] branch master updated (9d3e2689e -> 706cbf719), gnunet, 2024/12/04
- [taler-wallet-core] 02/15: Translated using Weblate (German), gnunet, 2024/12/04
- [taler-wallet-core] 01/15: Translated using Weblate (German), gnunet, 2024/12/04
- [taler-wallet-core] 06/15: add support for required input, show server measure on aml spa when doing debug, gnunet, 2024/12/04
- [taler-wallet-core] 08/15: accept tos kyc/aml form, gnunet, 2024/12/04
- [taler-wallet-core] 09/15: add prefix,
gnunet <=
- [taler-wallet-core] 04/15: wallet-core: parse useForeignAccount field, gnunet, 2024/12/04
- [taler-wallet-core] 03/15: wallet-core: allow treating bank accounts as foreign in withdrawal, gnunet, 2024/12/04
- [taler-wallet-core] 05/15: -small fixes from QC, gnunet, 2024/12/04
- [taler-wallet-core] 07/15: Translated using Weblate (German), gnunet, 2024/12/04
- [taler-wallet-core] 12/15: add kyc form, testing vqf, gnunet, 2024/12/04
- [taler-wallet-core] 11/15: Translated using Weblate (German), gnunet, 2024/12/04
- [taler-wallet-core] 13/15: fix program input interface, gnunet, 2024/12/04
- [taler-wallet-core] 14/15: test using multiple form in kyc measures, gnunet, 2024/12/04
- [taler-wallet-core] 15/15: Translated using Weblate (German), gnunet, 2024/12/04
- [taler-wallet-core] 10/15: test prefix, gnunet, 2024/12/04