Swedish interface: labels and short texts across every page
About 1,600 more headings, buttons, table columns, status words, placeholders and short messages are translated. Tables of words built when the app loads are now read when they are drawn, so they follow the language, and a test fails if text is translated at load time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
25183c0320
commit
6e39430a1f
173 files changed
+3922
-2245
No files matched your search
@@ -88,6 +88,34 @@ describe("the Swedish text", () => {
|
||||
assert.deepEqual(labels.filter((l) => !(l in sv)), [], "labels with no Swedish name");
|
||||
});
|
||||
|
||||
test("no text is translated when a module loads: a table of words built then would stay in the language of the first paint", async () => {
|
||||
const ts = (await import("typescript")).default;
|
||||
const { readdirSync } = await import("node:fs");
|
||||
const root = new URL("../../web/src/", import.meta.url);
|
||||
const files: URL[] = [];
|
||||
const walk = (dir: URL) => {
|
||||
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
||||
if (e.isDirectory()) {
|
||||
if (e.name !== "i18n") walk(new URL(`${e.name}/`, dir));
|
||||
} else if (/\.tsx?$/.test(e.name)) files.push(new URL(e.name, dir));
|
||||
}
|
||||
};
|
||||
walk(root);
|
||||
const offenders: string[] = [];
|
||||
for (const file of files) {
|
||||
const text = readFileSync(file, "utf8");
|
||||
if (!/\btn?\(/.test(text)) continue;
|
||||
const sf = ts.createSourceFile(file.pathname, text, ts.ScriptTarget.Latest, true, file.pathname.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
||||
const visit = (node: import("typescript").Node, inside: boolean) => {
|
||||
const fn = ts.isFunctionLike(node) || ts.isClassDeclaration(node);
|
||||
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && (node.expression.text === "t" || node.expression.text === "tn") && !inside) offenders.push(`${file.pathname.split("/web/src/")[1]}:${sf.getLineAndCharacterOfPosition(node.getStart()).line + 1}`);
|
||||
ts.forEachChild(node, (c) => visit(c, inside || fn));
|
||||
};
|
||||
visit(sf, false);
|
||||
}
|
||||
assert.deepEqual(offenders, [], "t() called outside any function; use a getter (get label() { return t(\"…\"); }) or translate where it is shown");
|
||||
});
|
||||
|
||||
test("translates the words the app's own lists show (the ranges, the density, the task states)", () => {
|
||||
for (const w of ["24 hours", "7 days", "30 days", "90 days", "1 year", "Compact", "Normal", "Roomy"]) assert.ok(w in sv, w);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user