[129] Grenze geschärft: React-freies i18n/translate, net/ im Kern, transitive Importprüfung
This commit is contained in:
11 files changed
+135
-95
No files matched your search
@@ -1075,8 +1075,9 @@ Prüfung des ganzen Programms (Rust-Kern, TS-Hülle, Build/Sicherheit), nur Code
|
||||
- ○ **[127] 3D-Booleans klären:** BSP in `fileio/csg.rs` stilllegen, Manifold vs. truck dokumentieren. · S
|
||||
- ○ **[128] Restlogik nach Rust:** Griffe (`useGripEditing.ts`), `layoutModel.ts`, Kollisions-Vorprüfung,
|
||||
`exportStep.projectSolidSpecs`. · L
|
||||
- ○ **[129] Grenze schärfen:** React-freies `t()` (Kern importiert `i18n` → React), `net/` in `CORE_DIRS`,
|
||||
transitive Importe prüfen. · S
|
||||
- ✅ **[129] Grenze schärfen.** (3.11.) `i18n/translate.ts` (React-frei: `t`, Sprache, Wörterbücher), `i18n/index.ts` re-exportiert
|
||||
und hält nur `useT`; Kern-Dateien importieren `i18n/translate`. `net/` in `CORE_DIRS`, neuer Test prüft transitive
|
||||
relative Importe (Ausnahmelisten leer). · S
|
||||
- ○ **[130] Kleinkram:** eine generische Fenster-Brücke statt 5 Kopien; Auswahl als ein `Selection`-Objekt statt
|
||||
12 Felder; `primitives.tsx` auf Overlay zurückschneiden; Cargo-Workspace + cargo-deny; NOTICE (OFL-Schriften,
|
||||
wgpu, Tauri, React, pdf.js, lcms). · M
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// Der Aufruf gehört in EIN `setProject` (ein Undo-Schritt).
|
||||
|
||||
import type { Drawing2D, DrawingLevel, Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import { t } from "../i18n/translate";
|
||||
import { applyOps } from "../core/ops";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { addItems } from "../core/opsBuild";
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Wächter für die Kern/Hülle-Grenze (docs/core-ui-split.md, Phase A). Es gibt kein ESLint im
|
||||
// Projekt — die Regeln laufen deshalb als Test über die Importzeilen aller Quelldateien.
|
||||
//
|
||||
// 1. Der KERN (model, geometry, plan, io, export, analysis, materials, text, engine) importiert
|
||||
// 1. Der KERN (core, model, geometry, plan, io, export, analysis, materials, text, engine, net) — auch
|
||||
// transitiv über relative Importe importiert
|
||||
// nie die HÜLLE (ui, panels, views, menus, editors, viewport, native, tools, state, commands,
|
||||
// App) und nie React/Zustand/Tauri statisch.
|
||||
// 2. Die HÜLLE holt Funktionen aus `plan/` und `geometry/` nur über die Fassade `src/core`.
|
||||
@@ -14,7 +15,7 @@ import { readdirSync, readFileSync, statSync } from "node:fs";
|
||||
import { dirname, join, normalize, relative, sep } from "node:path";
|
||||
|
||||
const SRC = join(process.cwd(), "src");
|
||||
const CORE_DIRS = new Set(["core", "model", "geometry", "plan", "io", "export", "analysis", "materials", "text", "engine"]);
|
||||
const CORE_DIRS = new Set(["core", "model", "geometry", "plan", "io", "export", "analysis", "materials", "text", "engine", "net"]);
|
||||
const SHELL_DIRS = new Set(["ui", "panels", "views", "menus", "editors", "viewport", "native", "tools", "state", "commands"]);
|
||||
const FACADE_DIRS = new Set(["plan", "geometry"]);
|
||||
const FORBIDDEN_PACKAGES = /^(react|react-dom|zustand|@tauri-apps\/.*)$/;
|
||||
@@ -80,6 +81,43 @@ describe("Kern/Hülle-Grenze", () => {
|
||||
expect(violations).toEqual([]);
|
||||
});
|
||||
|
||||
it("der Kern erreicht transitiv keine Hülle und keine UI-Pakete", () => {
|
||||
const violations: string[] = [];
|
||||
const resolve = (target: string): string | null => {
|
||||
for (const c of [`${target}.ts`, `${target}.tsx`, `${target}/index.ts`, `${target}/index.tsx`, target]) {
|
||||
const abs = join(SRC, c);
|
||||
try {
|
||||
if (statSync(abs).isFile()) return abs;
|
||||
} catch {
|
||||
/* nächster Kandidat */
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
for (const root of files) {
|
||||
if (!CORE_DIRS.has(top(root))) continue;
|
||||
const seen = new Set<string>([root]);
|
||||
const queue: Array<{ file: string; path: string[] }> = [{ file: root, path: [] }];
|
||||
while (queue.length) {
|
||||
const { file, path } = queue.shift()!;
|
||||
for (const i of importsOf(file)) {
|
||||
const tt = i.target?.split("/")[0];
|
||||
const chain = () => [relative(SRC, root), ...path, i.target ?? i.spec].join(" → ");
|
||||
if (tt && (SHELL_DIRS.has(tt) || tt === "App" || tt === "main")) violations.push(chain());
|
||||
else if (!i.target && FORBIDDEN_PACKAGES.test(i.spec)) violations.push(chain());
|
||||
else if (i.target) {
|
||||
const next = resolve(i.target);
|
||||
if (next && !seen.has(next) && !/\.test\.tsx?$/.test(next)) {
|
||||
seen.add(next);
|
||||
queue.push({ file: next, path: [...path, i.target] });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
expect([...new Set(violations)]).toEqual([]);
|
||||
});
|
||||
|
||||
it("die Hülle holt plan/ und geometry/ nur über die Fassade src/core", () => {
|
||||
const violations: string[] = [];
|
||||
for (const f of files) {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
import { jsPDF } from "jspdf";
|
||||
import type { Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import { t } from "../i18n/translate";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { computeAreaTable, computeIvhb } from "../analysis/areaTable";
|
||||
import type { AreaRow, IvhbOptions } from "../analysis/areaTable";
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// (wie die Fenster-/Türliste, `openingSchedule.ts`).
|
||||
|
||||
import type { Layer, Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import { t } from "../i18n/translate";
|
||||
import { documentFor } from "../core/document";
|
||||
import type { AreaReport, Cell, ReportRow } from "./areaReport";
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
import { jsPDF } from "jspdf";
|
||||
import "svg2pdf.js";
|
||||
import type { Layout, LayoutPaperFormat, MasterLayout, Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import { t } from "../i18n/translate";
|
||||
import { legendPlan, legendPrintSvg } from "./legendSvg";
|
||||
import { categoryLayerGroups, enablePdfLayers, type PdfLayers } from "./pdfLayers";
|
||||
import { generatePlan, type Plan } from "../plan/generatePlan";
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// (`areaReport.ts`: `areaReportToCsv` / `areaReportToSvg` / `buildAreaReportPdf`).
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import { t } from "../i18n/translate";
|
||||
import { documentFor } from "../core/document";
|
||||
import type { AreaReport, Cell, ReportRow, ReportSection } from "./areaReport";
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Die Zahlen rechnet der Kern (`analysis/roomProgram.ts`); hier nur die Beschriftung mit `t()`.
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import { t } from "../i18n/translate";
|
||||
import { compareRoomProgram } from "../analysis/roomProgram";
|
||||
import type { CompareSum, Light } from "../analysis/roomProgram";
|
||||
import type { AreaReport, Cell, ReportRow, ReportSection } from "./areaReport";
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { jsPDF } from "jspdf";
|
||||
import type { Layout, LayoutTable, LayoutTableSource, Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import { t } from "../i18n/translate";
|
||||
import { documentFor } from "../core/document";
|
||||
|
||||
export type { LayoutTable, LayoutTableSource };
|
||||
|
||||
+5
-84
@@ -1,94 +1,15 @@
|
||||
// i18n-Schicht — eine einzige Übersetzungsfunktion `t(key, params?)` plus ein
|
||||
// optionaler React-Hook `useT`. Default-Sprache ist Deutsch; das deutsche
|
||||
// Wörterbuch (de.ts) hält die EXAKTEN bisherigen UI-Texte, sodass die Umstellung
|
||||
// optisch nichts ändert. en.ts beweist die Übersetzbarkeit.
|
||||
//
|
||||
// Bewusst minimal gehalten: ein modulweiter „current language" + Wörterbuch-
|
||||
// Lookup mit {param}-Interpolation. Kein Provider-Zwang — t(...) ist überall
|
||||
// direkt aufrufbar; useT() liefert dieselbe Funktion und re-rendert Komponenten
|
||||
// beim Sprachwechsel (subscribe), falls je ein Umschalter gebaut wird.
|
||||
//
|
||||
// Identifier/Keys bleiben englisch (DOSSIER-Namespacing); nur die Wörterbuch-
|
||||
// Werte sind übersetzbarer Text.
|
||||
// i18n-Fassade: React-freier Kern in ./translate (für Kern-Module), dazu der React-Hook `useT`.
|
||||
|
||||
import { useSyncExternalStore } from "react";
|
||||
import { de } from "./de";
|
||||
import { en } from "./en";
|
||||
import type { TranslationKey } from "./de";
|
||||
import { getLanguage, subscribeLanguage, t } from "./translate";
|
||||
|
||||
export type { TranslationKey } from "./de";
|
||||
|
||||
/** Unterstützte Sprachen. Default ist „de". */
|
||||
export type Language = "de" | "en";
|
||||
|
||||
/** Wörterbücher je Sprache. de ist die Quelle der Keys (Default-Sprache). */
|
||||
const DICTS: Record<Language, Record<TranslationKey, string>> = { de, en };
|
||||
|
||||
/** Werte für die Platzhalter-Interpolation (`{name}` → params.name). */
|
||||
export type TParams = Record<string, string | number>;
|
||||
|
||||
// ── Modulweiter Sprachzustand + Abonnenten (für useT) ──────────────────────
|
||||
|
||||
let currentLanguage: Language = "de";
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
/** Aktuell gewählte Sprache. */
|
||||
export function getLanguage(): Language {
|
||||
return currentLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprache umschalten. Benachrichtigt abonnierte Komponenten (useT), damit sie
|
||||
* mit den neuen Texten neu rendern. (Noch kein UI-Umschalter — die Naht ist
|
||||
* aber vorhanden und verdrahtet.)
|
||||
*/
|
||||
export function setLanguage(lang: Language): void {
|
||||
if (lang === currentLanguage) return;
|
||||
currentLanguage = lang;
|
||||
for (const l of listeners) l();
|
||||
}
|
||||
|
||||
// ── Kern: Lookup + Interpolation ───────────────────────────────────────────
|
||||
|
||||
/** Ersetzt `{name}`-Platzhalter im Wert durch die übergebenen Parameter. */
|
||||
function interpolate(value: string, params?: TParams): string {
|
||||
if (!params) return value;
|
||||
return value.replace(/\{(\w+)\}/g, (match, name: string) =>
|
||||
name in params ? String(params[name]) : match,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Übersetzt einen Key in der aktuellen Sprache mit optionaler {param}-
|
||||
* Interpolation. Fehlt der Key in der gewählten Sprache, greift Deutsch als
|
||||
* Fallback; fehlt er auch dort, wird der Key selbst zurückgegeben (sichtbar,
|
||||
* damit fehlende Texte auffallen statt leer zu bleiben).
|
||||
*/
|
||||
export function t(key: TranslationKey | string, params?: TParams): string {
|
||||
const dict = DICTS[currentLanguage];
|
||||
const value =
|
||||
(dict as Record<string, string>)[key] ??
|
||||
(de as Record<string, string>)[key] ??
|
||||
key;
|
||||
return interpolate(value, params);
|
||||
}
|
||||
|
||||
// ── React-Hook ─────────────────────────────────────────────────────────────
|
||||
export * from "./translate";
|
||||
|
||||
/**
|
||||
* Hook-Variante: liefert dieselbe `t`-Funktion, abonniert aber den
|
||||
* Sprachzustand, sodass die Komponente beim Sprachwechsel neu rendert. In den
|
||||
* meisten Komponenten reicht der direkte `t`-Import; useT() ist für den Fall
|
||||
* gedacht, dass ein Live-Sprachumschalter existiert.
|
||||
* Sprachzustand, sodass die Komponente beim Sprachwechsel neu rendert.
|
||||
*/
|
||||
export function useT(): typeof t {
|
||||
useSyncExternalStore(
|
||||
(cb) => {
|
||||
listeners.add(cb);
|
||||
return () => listeners.delete(cb);
|
||||
},
|
||||
getLanguage,
|
||||
getLanguage,
|
||||
);
|
||||
useSyncExternalStore(subscribeLanguage, getLanguage, getLanguage);
|
||||
return t;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// i18n-Kern (React-frei) — von Kern-Modulen importierbar. Der Hook `useT` liegt in index.ts.
|
||||
// i18n-Schicht — eine einzige Übersetzungsfunktion `t(key, params?)` plus ein
|
||||
// optionaler React-Hook `useT`. Default-Sprache ist Deutsch; das deutsche
|
||||
// Wörterbuch (de.ts) hält die EXAKTEN bisherigen UI-Texte, sodass die Umstellung
|
||||
// optisch nichts ändert. en.ts beweist die Übersetzbarkeit.
|
||||
//
|
||||
// Bewusst minimal gehalten: ein modulweiter „current language" + Wörterbuch-
|
||||
// Lookup mit {param}-Interpolation. Kein Provider-Zwang — t(...) ist überall
|
||||
// direkt aufrufbar; useT() liefert dieselbe Funktion und re-rendert Komponenten
|
||||
// beim Sprachwechsel (subscribe), falls je ein Umschalter gebaut wird.
|
||||
//
|
||||
// Identifier/Keys bleiben englisch (DOSSIER-Namespacing); nur die Wörterbuch-
|
||||
// Werte sind übersetzbarer Text.
|
||||
|
||||
import { de } from "./de";
|
||||
import { en } from "./en";
|
||||
import type { TranslationKey } from "./de";
|
||||
|
||||
export type { TranslationKey } from "./de";
|
||||
|
||||
/** Unterstützte Sprachen. Default ist „de". */
|
||||
export type Language = "de" | "en";
|
||||
|
||||
/** Wörterbücher je Sprache. de ist die Quelle der Keys (Default-Sprache). */
|
||||
const DICTS: Record<Language, Record<TranslationKey, string>> = { de, en };
|
||||
|
||||
/** Werte für die Platzhalter-Interpolation (`{name}` → params.name). */
|
||||
export type TParams = Record<string, string | number>;
|
||||
|
||||
// ── Modulweiter Sprachzustand + Abonnenten (für useT) ──────────────────────
|
||||
|
||||
let currentLanguage: Language = "de";
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
/** Aktuell gewählte Sprache. */
|
||||
export function getLanguage(): Language {
|
||||
return currentLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprache umschalten. Benachrichtigt abonnierte Komponenten (useT), damit sie
|
||||
* mit den neuen Texten neu rendern. (Noch kein UI-Umschalter — die Naht ist
|
||||
* aber vorhanden und verdrahtet.)
|
||||
*/
|
||||
export function setLanguage(lang: Language): void {
|
||||
if (lang === currentLanguage) return;
|
||||
currentLanguage = lang;
|
||||
for (const l of listeners) l();
|
||||
}
|
||||
|
||||
// ── Kern: Lookup + Interpolation ───────────────────────────────────────────
|
||||
|
||||
/** Ersetzt `{name}`-Platzhalter im Wert durch die übergebenen Parameter. */
|
||||
function interpolate(value: string, params?: TParams): string {
|
||||
if (!params) return value;
|
||||
return value.replace(/\{(\w+)\}/g, (match, name: string) =>
|
||||
name in params ? String(params[name]) : match,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Übersetzt einen Key in der aktuellen Sprache mit optionaler {param}-
|
||||
* Interpolation. Fehlt der Key in der gewählten Sprache, greift Deutsch als
|
||||
* Fallback; fehlt er auch dort, wird der Key selbst zurückgegeben (sichtbar,
|
||||
* damit fehlende Texte auffallen statt leer zu bleiben).
|
||||
*/
|
||||
export function t(key: TranslationKey | string, params?: TParams): string {
|
||||
const dict = DICTS[currentLanguage];
|
||||
const value =
|
||||
(dict as Record<string, string>)[key] ??
|
||||
(de as Record<string, string>)[key] ??
|
||||
key;
|
||||
return interpolate(value, params);
|
||||
}
|
||||
|
||||
/** Abo für den Sprachzustand (für `useT`). */
|
||||
export function subscribeLanguage(cb: () => void): () => void {
|
||||
listeners.add(cb);
|
||||
return () => listeners.delete(cb);
|
||||
}
|
||||
Reference in new issue
Block a user