GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(catalog): the parameter tables follow the app language · u8array/ZPLab@a7ca5c6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/core/src/catalog
    • commands.json
    • schema.ts
  • scripts
    • catalog-reference-hash.d.mts
    • catalog-reference-hash.mjs
    • catalog-reference-merge.mjs
    • catalog.d.mts
    • catalog.mjs
  • src
    • components/Output
      • ZplCatalog.test.tsx
      • ZplCatalogDetail.tsx
    • hooks
      • useCatalogSummaries.test.tsx
      • useCatalogSummaries.ts
    • lib
      • catalogText.test.ts
      • catalogText.ts
    • locales
      • catalogSummaries.test.ts
      • catalogSummaries.ts
      • catalog
        • ar.json
        • bg.json
        • cs.json
        • da.json
        • de.json
        • el.json
        • es.json
        • et.json
        • fa.json
        • fi.json
        • fr.json
        • he.json
        • hr.json
        • hu.json
        • it.json
        • ja.json
        • ko.json
        • lt.json
        • lv.json
        • nl.json
        • no.json
        • pl.json
        • pt.json
        • ro.json
        • sk.json
        • sl.json
        • sr.json
        • sv.json
        • tr.json
        • zh-hans.json
        • zh-hant.json

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/catalog/commands.json‎

Copy file name to clipboardExpand all lines: packages/core/src/catalog/commands.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@
16921692
{
16931693
"name": "m",
16941694
"meaning": "mode",
1695-
"values": "N none, U UCC case, A automatic, D UCC/EAN",
1695+
"values": "N none, U UCC Case Mode, A automatic, D UCC/EAN",
16961696
"default": "N"
16971697
}
16981698
],
@@ -3087,7 +3087,7 @@
30873087
{
30883088
"name": "r",
30893089
"meaning": "corner rounding",
3090-
"values": "0 none to 8 heaviest",
3090+
"values": "0 none to 8 strongest rounding",
30913091
"default": "0"
30923092
}
30933093
],
Collapse file

‎packages/core/src/catalog/schema.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/catalog/schema.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type ImportLossCause = (typeof IMPORT_LOSS_CAUSES)[number];
1313
const supportSchema = z.object({ web: z.enum(SUPPORT_LEVELS), desktop: z.enum(SUPPORT_LEVELS), docker: z.enum(SUPPORT_LEVELS).optional() }).strict();
1414
export type CommandSupport = Required<z.infer<typeof supportSchema>>;
1515

16-
/** Slot letters of the format line in order. English only like `title`, so no translated channel. */
16+
/** Slot letters of the format line in order. `name` stays English like `title`; the other cells are translated per locale, keyed by the English block. */
1717
const paramSchema = z.object({
1818
name: z.string().min(1),
1919
meaning: z.string().min(1),
Collapse file

‎scripts/catalog-reference-hash.d.mts‎

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Types for the node-only hash helper, so the translation test can import it under the app tsconfig.
2+
import type { CommandReference } from "../packages/core/src/catalog/schema";
3+
4+
export declare function textHash(text: string): string;
5+
export declare function referenceParamsText(reference: CommandReference): string;
6+
export declare function referenceHash(reference: CommandReference): string;
7+
export declare function referenceTokens(text: string): Set<string>;
Collapse file

‎scripts/catalog-reference-hash.mjs‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createHash } from "node:crypto";
2+
3+
/** The one hash scheme every catalog translation is pinned with. */
4+
export function textHash(text) {
5+
return createHash("sha256").update(text).digest("hex").slice(0, 8);
6+
}
7+
8+
/** One text per reference block, so the test and the merge script pin the same English. */
9+
export function referenceParamsText(reference) {
10+
return JSON.stringify(reference.params.map((p) => [p.meaning, p.values, p.default ?? ""]));
11+
}
12+
13+
export function referenceHash(reference) {
14+
return textHash(referenceParamsText(reference));
15+
}
16+
17+
/** The codes and numbers the user types, so a translation may not drop them. Two letter runs stay out: words like ID get translated. */
18+
export function referenceTokens(text) {
19+
return new Set(text.match(/-?\d+(?:\.\d+)?|[\^~][A-Z@][A-Z0-9]|\b[A-Z](?=[\s,.]|$)|\b[A-Z][A-Z0-9/-]{2,}\b/g) ?? []);
20+
}
Collapse file

‎scripts/catalog-reference-merge.mjs‎

Copy file name to clipboard
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env node
2+
// The only writer that may stamp a reference hash.
3+
// Usage: node scripts/catalog-reference-merge.mjs todo <locale> prints the blocks still to translate
4+
// node scripts/catalog-reference-merge.mjs merge <locale> <in.json> writes them into src/locales/catalog/<locale>.json
5+
import { readFileSync, writeFileSync } from "node:fs";
6+
import { join } from "node:path";
7+
import { ROOT, commandId, readCatalog } from "./catalog.mjs";
8+
import { referenceHash } from "./catalog-reference-hash.mjs";
9+
10+
const [mode, locale, input] = process.argv.slice(2);
11+
if (!["todo", "merge"].includes(mode) || !locale || (mode === "merge" && !input)) throw new Error("usage: todo <locale> | merge <locale> <in.json>");
12+
const catalog = readCatalog().commands.filter((c) => c.reference?.params.length);
13+
const file = join(ROOT, "src", "locales", "catalog", `${locale}.json`);
14+
const rows = JSON.parse(readFileSync(file, "utf8"));
15+
const current = (c) => rows[commandId(c)]?.reference?.hash === referenceHash(c.reference);
16+
17+
if (mode === "todo") {
18+
const todo = Object.fromEntries(
19+
catalog.filter((c) => !current(c)).map((c) => [commandId(c), c.reference.params.map((p) => ({ name: p.name, meaning: p.meaning, values: p.values, ...(p.default ? { default: p.default } : {}) }))]),
20+
);
21+
process.stdout.write(JSON.stringify(todo, null, 1) + "\n");
22+
} else {
23+
const translated = JSON.parse(readFileSync(input, "utf8"));
24+
const known = new Set(catalog.map(commandId));
25+
const unknown = Object.keys(translated).filter((id) => !known.has(id));
26+
if (unknown.length > 0) throw new Error(`no table to translate for ${unknown.join(", ")}`);
27+
for (const c of catalog) {
28+
const id = commandId(c);
29+
const params = translated[id];
30+
if (!params) continue;
31+
if (!rows[id]) throw new Error(`${id}: no summary row to attach the table to`);
32+
checkParams(id, params, c.reference.params);
33+
rows[id] = {
34+
...rows[id],
35+
reference: { hash: referenceHash(c.reference), params: params.map((p) => ({ meaning: p.meaning, values: p.values, ...(p.default !== undefined ? { default: p.default } : {}) })) },
36+
};
37+
}
38+
// The catalog order keeps the diff readable. A row whose command left the catalog drops out.
39+
const ordered = Object.fromEntries(readCatalog().commands.map((c) => [commandId(c), rows[commandId(c)]]).filter(([, row]) => row));
40+
writeFileSync(file, JSON.stringify(ordered, null, 2) + "\n");
41+
console.log(`${locale}: ${Object.keys(translated).length} reference blocks written`);
42+
}
43+
44+
function checkParams(id, params, english) {
45+
if (params.length !== english.length) throw new Error(`${id}: ${params.length} params, catalog has ${english.length}`);
46+
// Siblings often share values and default, so only the slot name tells a reordered table apart.
47+
params.forEach((p, i) => {
48+
if (p.name !== undefined && p.name !== english[i].name) throw new Error(`${id}: slot ${i} is ${p.name}, catalog has ${english[i].name}`);
49+
if (!p.meaning?.trim() || !p.values?.trim()) throw new Error(`${id} ${english[i].name}: empty meaning or values`);
50+
if ((p.default === undefined) !== (english[i].default === undefined)) throw new Error(`${id} ${english[i].name}: default presence differs from the catalog`);
51+
});
52+
}
Collapse file

‎scripts/catalog.d.mts‎

Copy file name to clipboardExpand all lines: scripts/catalog.d.mts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Types for the node-only catalog loader, so the parity test can import it under the app tsconfig.
22
import type { Catalog, ZplCommandEntry } from "../packages/core/src/catalog/schema";
33

4+
export declare const ROOT: string;
45
export declare const CAPABILITIES: readonly ["web", "desktop", "docker"];
56
export declare const commandId: (entry: ZplCommandEntry) => string;
67
export declare const commandIds: (entry: ZplCommandEntry) => string[];
Collapse file

‎scripts/catalog.mjs‎

Copy file name to clipboardExpand all lines: scripts/catalog.mjs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { readFileSync } from 'node:fs';
44
import { join } from 'node:path';
55
import { fileURLToPath } from 'node:url';
66

7-
const ROOT = fileURLToPath(new URL('..', import.meta.url));
7+
export const ROOT = fileURLToPath(new URL('..', import.meta.url));
88
const CATALOG = join(ROOT, 'packages', 'core', 'src', 'catalog', 'commands.json');
99
export const CAPABILITIES = ['web', 'desktop', 'docker'];
1010
const LEVELS = new Set(['yes', 'planned', 'no']);
Collapse file

‎src/components/Output/ZplCatalog.test.tsx‎

Copy file name to clipboardExpand all lines: src/components/Output/ZplCatalog.test.tsx
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import { ZplCatalogList } from "./ZplCatalogList";
55
import { ZplCatalogDetail } from "./ZplCatalogDetail";
66
import { useCatalogSelection } from "../../hooks/useCatalogSelection";
77
import type { CursorCommand } from "../../lib/zplLanguage";
8+
import { useCatalogSummaries } from "../../hooks/useCatalogSummaries";
9+
10+
vi.mock("../../hooks/useCatalogSummaries", () => ({ useCatalogSummaries: vi.fn(() => ({})) }));
811

912
afterEach(() => {
1013
cleanup();
14+
vi.mocked(useCatalogSummaries).mockReturnValue({});
1115
localStorage.removeItem("zpl:section:catalog-list");
1216
localStorage.removeItem("zpl:section:catalog-detail");
1317
});
@@ -57,6 +61,26 @@ describe("catalog panes", () => {
5761
expect(second.queryByRole("list")).toBeNull();
5862
});
5963

64+
it("shows the parameter table in the loaded language and falls back to English row by row", () => {
65+
vi.mocked(useCatalogSummaries).mockReturnValue({
66+
"^FO": { hash: "x", summary: "Setzt die Feldposition.", reference: { hash: "y", params: [
67+
{ meaning: "horizontale Position in Punkten", values: "0 bis 32000", default: "0" },
68+
{ meaning: "vertikale Position in Punkten", values: "0 bis 32000", default: "0" },
69+
{ meaning: "Ausrichtung", values: "0 links, 1 rechts, 2 automatisch", default: "letztes ^FW" },
70+
] } },
71+
});
72+
const r = render(<CatalogPanes cursor={{ id: "^FO", from: 0, pointed: true }} onInsert={vi.fn()} />);
73+
expect(detail(r.getByTestId).getByText("horizontale Position in Punkten")).toBeTruthy();
74+
expect(detail(r.getByTestId).getByText(/0 links, 1 rechts, 2 automatisch/)).toBeTruthy();
75+
r.unmount();
76+
vi.mocked(useCatalogSummaries).mockReturnValue({ "^FO": { hash: "x", summary: "Setzt die Feldposition.", reference: { hash: "y", params: [
77+
{ meaning: "horizontale Position in Punkten", values: "0 bis 32000", default: "0" },
78+
] } } });
79+
const mixed = render(<CatalogPanes cursor={{ id: "^FO", from: 0, pointed: true }} onInsert={vi.fn()} />);
80+
expect(detail(mixed.getByTestId).getByText("horizontale Position in Punkten")).toBeTruthy();
81+
expect(detail(mixed.getByTestId).getByText("vertical position in dots")).toBeTruthy();
82+
});
83+
6084
it("folds the command list to a rail, keeps the description and remembers the fold", () => {
6185
const first = render(<CatalogPanes cursor={{ id: "^LL", from: 0, pointed: true }} onInsert={vi.fn()} />);
6286
fireEvent.click(first.getByRole("button", { name: "Command list" }));
Collapse file

‎src/components/Output/ZplCatalogDetail.tsx‎

Copy file name to clipboardExpand all lines: src/components/Output/ZplCatalogDetail.tsx
+9-8Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { commandId, commandLabel, type CommandSupport } from "@zplab/core/catalo
33
import { useT } from "../../hooks/useT";
44
import { useCatalogSummaries } from "../../hooks/useCatalogSummaries";
55
import type { CatalogSelection } from "../../hooks/useCatalogSelection";
6-
import { catalogEmptyText, syntaxSegments } from "../../lib/catalogText";
6+
import { catalogEmptyText, referenceRows, syntaxSegments } from "../../lib/catalogText";
77
import { useCollapsibleState } from "../ui/useCollapsibleState";
88
import { PaneToggle } from "../ui/PaneToggle";
99
import { sectionHeadingCls } from "../ui/formStyles";
@@ -22,6 +22,7 @@ export function ZplCatalogDetail({ selection, editorHasFocus }: { selection: Cat
2222
const bodyId = useId();
2323
const [open, setOpen] = useCollapsibleState("catalog-detail", true);
2424
const { entry, emptyReason, stepBack } = selection;
25+
const translated = entry ? summaries[commandId(entry)] : undefined;
2526
const emptyLine = emptyReason && <p className="text-muted leading-relaxed">{catalogEmptyText(emptyReason, t)}</p>;
2627
// The no-cursor line would be read on every step through plain text.
2728
const announced = emptyReason?.kind !== "noCursor";
@@ -56,7 +57,7 @@ export function ZplCatalogDetail({ selection, editorHasFocus }: { selection: Cat
5657
<span className="font-mono text-accent font-semibold shrink-0">{commandLabel(entry)}</span>
5758
<span className="text-text font-medium">{entry.title}</span>
5859
</div>
59-
<p className="mt-1.5 text-text leading-relaxed">{summaries[commandId(entry)]?.summary ?? entry.summary}</p>
60+
<p className="mt-1.5 text-text leading-relaxed">{translated?.summary ?? entry.summary}</p>
6061
</>
6162
)}
6263
{announced && emptyLine}
@@ -73,14 +74,14 @@ export function ZplCatalogDetail({ selection, editorHasFocus }: { selection: Cat
7374
</code>
7475
{entry.reference.params.length > 0 && (
7576
<ul className="mt-2.5 space-y-2">
76-
{entry.reference.params.map((p, i) => (
77-
<li key={p.name} className="grid grid-cols-[0.875rem_1fr] gap-x-2 items-baseline">
78-
<span className={`font-mono font-semibold ${slotClass(i)}`}>{p.name}</span>
79-
<span className="text-text leading-snug">{p.meaning}</span>
77+
{referenceRows(entry.reference.params, translated).map((row, i) => (
78+
<li key={row.name} className="grid grid-cols-[0.875rem_1fr] gap-x-2 items-baseline">
79+
<span className={`font-mono font-semibold ${slotClass(i)}`}>{row.name}</span>
80+
<span className="text-text leading-snug">{row.meaning}</span>
8081
<span className="col-start-2 mt-0.5 text-[11px] text-muted leading-snug">
81-
{p.values}
82+
{row.values}
8283
{/* Without nowrap the separator can end a line and orphan the default. */}
83-
{p.default && <span className="whitespace-nowrap">{` \u00b7 ${t.output.catalogDefault} ${p.default}`}</span>}
84+
{row.default && <span className="whitespace-nowrap">{` \u00b7 ${t.output.catalogDefault} ${row.default}`}</span>}
8485
</span>
8586
</li>
8687
))}
Collapse file

‎src/hooks/useCatalogSummaries.test.tsx‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @vitest-environment jsdom
2+
import { describe, it, expect, afterEach, vi } from "vitest";
3+
import { renderHook, act, cleanup, waitFor } from "@testing-library/react";
4+
import { useLabelStore } from "../store/labelStore";
5+
import { useCatalogSummaries } from "./useCatalogSummaries";
6+
import type * as CatalogSummariesModule from "../locales/catalogSummaries";
7+
8+
const { pending } = vi.hoisted(() => ({ pending: new Map<string, (rows: Record<string, unknown>) => void>() }));
9+
vi.mock("../locales/catalogSummaries", async (importOriginal) => ({
10+
...(await importOriginal<typeof CatalogSummariesModule>()),
11+
loadCatalogSummaries: (locale: string) => new Promise((resolve) => pending.set(locale, resolve)),
12+
}));
13+
14+
afterEach(() => {
15+
cleanup();
16+
pending.clear();
17+
act(() => useLabelStore.setState({ loadedLocale: "en" }));
18+
});
19+
20+
describe("useCatalogSummaries", () => {
21+
it("shows nothing of the previous language while the next chunk loads", async () => {
22+
act(() => useLabelStore.setState({ loadedLocale: "de" }));
23+
const { result } = renderHook(() => useCatalogSummaries());
24+
await act(async () => pending.get("de")?.({ "^FO": { hash: "x", summary: "Setzt die Feldposition." } }));
25+
await waitFor(() => expect(result.current["^FO"]?.summary).toBe("Setzt die Feldposition."));
26+
27+
act(() => useLabelStore.setState({ loadedLocale: "fr" }));
28+
expect(result.current).toEqual({});
29+
await act(async () => pending.get("fr")?.({ "^FO": { hash: "x", summary: "Place le champ." } }));
30+
await waitFor(() => expect(result.current["^FO"]?.summary).toBe("Place le champ."));
31+
});
32+
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.