fix(i18n): parse imported locale sections in autofill

This commit is contained in:
zipg 2026-08-07 13:54:37 +08:00 committed by GitHub
parent 9bb1b7aa91
commit 4ae3e33103
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 4 deletions

View File

@ -201,9 +201,7 @@ function assertSamePlaceholders(key, source, translated, locale) {
const sourcePlaceholders = placeholders(source);
const translatedPlaceholders = placeholders(translated);
if (sourcePlaceholders.join("\0") !== translatedPlaceholders.join("\0")) {
throw new Error(
`${locale}:${key} placeholder mismatch: expected [${sourcePlaceholders.join(", ")}], got [${translatedPlaceholders.join(", ")}]`,
);
throw new Error(`${locale}:${key} placeholder mismatch: expected [${sourcePlaceholders.join(", ")}], got [${translatedPlaceholders.join(", ")}]`);
}
}
@ -362,7 +360,7 @@ function flattenNode(node, path, result) {
const nextPath = [...path, property.key];
if (property.value.type === "object") {
flattenNode(property.value, nextPath, result);
} else {
} else if (property.value.type === "string") {
result.set(nextPath.join("."), property.value.value);
}
}
@ -416,6 +414,12 @@ class Parser {
const start = this.index;
const key = this.parseKey();
this.skipSpace();
if (this.peek() === "," || this.peek() === "}") {
const hasComma = this.peek() === ",";
if (hasComma) this.index += 1;
properties.push({ key, start, end: this.index, hasComma, value: { type: "external" } });
continue;
}
this.expect(":");
this.skipSpace();
const value = this.parseValue();

View File

@ -0,0 +1,11 @@
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { test } from "vitest";
test("i18n autofill parses locale roots with imported shorthand sections", () => {
const output = execFileSync(process.execPath, [".github/scripts/i18n-autofill.mjs", "--dry-run", "--base-ref", "HEAD"], {
encoding: "utf8",
});
assert.match(output, /No new zh-CN i18n keys compared with HEAD/);
});