Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -3,7 +3,7 @@
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
import path from "node:path";
import { defaultLocale, i18nNamespaces, supportedLocales } from "../packages/i18n/src/index.ts";
import { catalogReadyLocales, defaultLocale, i18nNamespaces } from "../packages/i18n/src/index.ts";
export type JsonObject = Record<string, unknown>;
@@ -62,6 +62,13 @@ export type LocaleParityIssue =
namespace: string;
filePath: string;
keys: string[];
}
| {
type: "language-leak";
locale: string;
namespace: string;
filePath: string;
findings: Array<{ key: string; words: string[] }>;
};
export type LocaleKeySummary = {
@@ -93,6 +100,7 @@ type SourceTranslationKey = {
key: string;
namespace: string | null;
fallback: MissingSourceKeyFallback;
family: boolean;
};
const DEFAULT_SOURCE_ROOTS = ["apps/web/app", "packages"] as const;
@@ -101,6 +109,183 @@ const TEST_FILE_PATTERN = /\.(test|spec)\.(ts|tsx)$/;
const IGNORED_SOURCE_DIRS = new Set(["node_modules", "dist", "build", "coverage", ".cache", "generated"]);
const DEFAULT_NAMESPACE = "translations";
// High-confidence German UI vocabulary that must not appear in the English
// catalog. The match is intentionally case-sensitive: German UI labels and
// sentence starts are capitalized, while lower-case technical identifiers such
// as `kontakt.created` can legitimately appear in examples and audit filters.
// Keep this an explicit vocabulary instead of guessing language from all text;
// product names and established English/German loanwords stay false-positive
// free.
const GERMAN_UI_WORDS = [
"Abbrechen",
"Aktualisieren",
"Alle",
"Anmelden",
"Archiviert",
"Aufgabe",
"Aufgaben",
"Ausgewählt",
"Auswahl",
"Bearbeiten",
"Benutzer",
"Bereit",
"Bestätigen",
"Bitte",
"Datei",
"Dateien",
"Diese",
"Dieser",
"Dieses",
"Einstellungen",
"Erstellen",
"Fehlgeschlagen",
"Firma",
"Hinzufügen",
"Kein",
"Keine",
"Kontakt",
"Kontakte",
"Konto",
"Löschen",
"Neu",
"Neue",
"Neuer",
"Neues",
"Öffnen",
"Projekt",
"Projekte",
"Prüfe",
"Schließen",
"Senden",
"Speichern",
"Stornieren",
"Suchen",
"Telefonnummer",
"Unbekannt",
"Verantwortlicher",
"Verfügbar",
"Verknüpfung",
"Wähle",
"Zurück",
"Zustellung",
] as const;
const GERMAN_UI_WORD_PATTERN = new RegExp(`(?<![\\p{L}\\p{N}_])(?:${GERMAN_UI_WORDS.join("|")})(?![\\p{L}\\p{N}_])`, "gu");
// View-models and server registries often pass translation keys to the UI
// instead of calling `t()` at the declaration site. Keep this list explicit:
// names such as `featureFlagKey`, `triggerKey` or `idempotencyKey` are stable
// protocol identifiers and must not be mistaken for translation keys.
const TRANSLATION_KEY_FIELDS = [
"actionErrorKey",
"actionKey",
"actionLabelKey",
"actorKindLabelKey",
"anonymousHintKey",
"badgeLabelKey",
"blockedReasonKey",
"bodyKey",
"breadcrumbKey",
"buttonKey",
"captionKey",
"candidatesEmptyKey",
"candidatesLoadingKey",
"commentEmptyKey",
"complaintMessageKey",
"composerPlaceholderKey",
"conflictHintKey",
"conflictsEmptyKey",
"ctaKey",
"descriptionKey",
"designBlockedByKey",
"detailKey",
"disabledReasonKey",
"discoverHeadlineKey",
"dmModeKey",
"dmReadOnlyKey",
"dropzoneBodyKey",
"dropzoneHeadlineKey",
"emptyBodyKey",
"emptyCandidatesKey",
"emptyDescriptionKey",
"emptyHeadlineKey",
"emptyItemsBodyKey",
"emptyItemsHeadlineKey",
"emptyKey",
"emptyMembersKey",
"emptyRepliesBodyKey",
"emptyRepliesHeadlineKey",
"emptyTitleKey",
"environmentNoticeKey",
"errorKey",
"errorMessageKey",
"eyebrowKey",
"expiryKey",
"failureI18nKey",
"failureReasonKey",
"feedbackKey",
"groupModeKey",
"groupsEmptyKey",
"healthMessageKey",
"headlineKey",
"heicNoticeKey",
"helpDescriptionKey",
"helpKey",
"helpTextKey",
"helpTitleKey",
"hintKey",
"i18nKey",
"infoKey",
"infoTooltipKey",
"kindLabelKey",
"labelKey",
"lastErrorMessageKey",
"loadOlderLabelKey",
"manualGuestsHeadlineKey",
"membersEmptyKey",
"membersLoadingKey",
"messageKey",
"nameKey",
"newMessagesLabelKey",
"noAllowedModesKey",
"noMailboxBodyKey",
"noMailboxHeadlineKey",
"noMailboxKey",
"noMatchesKey",
"noPackageHintKey",
"noResultsBodyKey",
"noResultsHeadlineKey",
"noResultsKey",
"noResultsTitleKey",
"notConfiguredKey",
"overageNoticeKey",
"paymentStatusLabelKey",
"placeholderKey",
"priorityLabelKey",
"projectManagedExternallyKey",
"reasonKey",
"roleLabelKey",
"searchPlaceholderKey",
"sectionLabelKey",
"sourceLabelKey",
"stateLabelKey",
"statusLabelKey",
"submitKey",
"submittedHintKey",
"subtitleKey",
"successKey",
"successMessageKey",
"summaryKey",
"textKey",
"titleKey",
"tombstoneKey",
"translationKey",
"typeLabelKey",
"unreadEmptyKey",
"usersEmptyKey",
"usersLoadingKey",
] as const;
const TRANSLATION_KEY_FIELD_PATTERN = TRANSLATION_KEY_FIELDS.join("|");
function isJsonObject(value: unknown): value is JsonObject {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
@@ -123,7 +308,7 @@ export function collectLeafKeys(value: unknown, prefix = ""): string[] {
export function checkI18nParity(options: I18nParityOptions = {}): I18nParityResult {
const cwd = options.cwd ?? process.cwd();
const localesRoot = options.localesRoot ?? resolveLocalesRoot(cwd);
const locales = [...(options.locales ?? supportedLocales)];
const locales = [...(options.locales ?? catalogReadyLocales)];
const namespaces = [...(options.namespaces ?? i18nNamespaces)];
const configuredReferenceLocale = options.referenceLocale ?? defaultLocale;
const referenceLocale = locales.includes(configuredReferenceLocale) ? configuredReferenceLocale : locales[0] ?? configuredReferenceLocale;
@@ -183,6 +368,10 @@ export function checkI18nParity(options: I18nParityOptions = {}): I18nParityResu
if (emptyTranslationKeys.length > 0) {
issues.push({ type: "empty-translation", locale, namespace, filePath, keys: emptyTranslationKeys });
}
if (locale === "en") {
const findings = collectGermanLanguageLeaks(parsed);
if (findings.length > 0) issues.push({ type: "language-leak", locale, namespace, filePath, findings });
}
localeKeySets.set(namespace, new Set(leafKeys));
summaries.push({ locale, namespace, filePath, keyCount: leafKeys.length });
}
@@ -224,7 +413,7 @@ export function checkI18nParity(options: I18nParityOptions = {}): I18nParityResu
for (const [sourceKey, files] of collectStaticSourceTranslationKeys(cwd, options.sourceRoots ?? DEFAULT_SOURCE_ROOTS, namespaces)) {
if (!hasSourceTranslationKey(referenceNamespaces, sourceKey, namespaces)) {
issues.push({ type: "missing-source-key", ...sourceKey, files });
issues.push({ type: "missing-source-key", key: sourceKey.key, namespace: sourceKey.namespace, fallback: sourceKey.fallback, files });
}
}
}
@@ -241,7 +430,7 @@ export function checkI18nParity(options: I18nParityOptions = {}): I18nParityResu
function hasSourceTranslationKey(referenceNamespaces: Map<string, Set<string>>, sourceKey: SourceTranslationKey, namespaces: readonly string[]) {
if (sourceKey.namespace) {
return hasTranslationKey(referenceNamespaces.get(sourceKey.namespace) ?? new Set<string>(), sourceKey.key);
return hasTranslationKey(referenceNamespaces.get(sourceKey.namespace) ?? new Set<string>(), sourceKey.key, sourceKey.family);
}
// Laufzeit-Semantik (i18next): der Namespace wird mit ":" getrennt (nsSeparator), NICHT mit ".".
@@ -250,10 +439,14 @@ function hasSourceTranslationKey(referenceNamespaces: Map<string, Set<string>>,
// Key deshalb nur als vollständigen Key in den (effektiven) Namespaces. KEIN "erstes Punkt-Segment
// als Namespace"-Fallback: der würde einen Punkt-statt-Doppelpunkt-Fehler (im UI ein nackter Key)
// stillschweigend als gültig durchwinken -- genau die Lücke, die den Theme-Settings-Bug verdeckte.
return namespaces.some((namespace) => hasTranslationKey(referenceNamespaces.get(namespace) ?? new Set<string>(), sourceKey.key));
return namespaces.some((namespace) => hasTranslationKey(referenceNamespaces.get(namespace) ?? new Set<string>(), sourceKey.key, sourceKey.family));
}
function hasTranslationKey(keys: Set<string>, key: string) {
function hasTranslationKey(keys: Set<string>, key: string, family = false) {
if (family) {
const pattern = new RegExp(`^${escapeRegExp(key).replaceAll("\\*", ".+")}$`, "u");
return [...keys].some((candidate) => pattern.test(candidate));
}
return keys.has(key) || keys.has(`${key}_one`) || keys.has(`${key}_other`);
}
@@ -267,6 +460,18 @@ function collectEmptyTranslationKeys(value: unknown, prefix = ""): string[] {
.flatMap((key) => collectEmptyTranslationKeys(value[key], prefix ? `${prefix}.${key}` : key));
}
function collectGermanLanguageLeaks(value: unknown, prefix = ""): Array<{ key: string; words: string[] }> {
if (!isJsonObject(value)) {
if (typeof value !== "string" || !prefix) return [];
const words = [...new Set([...value.matchAll(GERMAN_UI_WORD_PATTERN)].map((match) => match[0]))];
return words.length > 0 ? [{ key: prefix, words }] : [];
}
return Object.keys(value)
.sort((left, right) => left.localeCompare(right))
.flatMap((key) => collectGermanLanguageLeaks(value[key], prefix ? `${prefix}.${key}` : key));
}
function collectStaticSourceTranslationKeys(cwd: string, sourceRoots: readonly string[], namespaces: readonly string[]) {
const keys = new Map<string, { sourceKey: SourceTranslationKey; files: string[] }>();
@@ -278,7 +483,7 @@ function collectStaticSourceTranslationKeys(cwd: string, sourceRoots: readonly s
const relativePath = slash(path.relative(cwd, filePath));
const source = readFileSync(filePath, "utf8");
for (const sourceKey of extractStaticTranslationKeys(source, namespaces)) {
const id = `${sourceKey.namespace ?? "*"}:${sourceKey.key}:${sourceKey.fallback}`;
const id = `${sourceKey.namespace ?? "*"}:${sourceKey.key}:${sourceKey.fallback}:${sourceKey.family ? "family" : "exact"}`;
const entry = keys.get(id) ?? { sourceKey, files: [] };
entry.files.push(relativePath);
keys.set(id, entry);
@@ -317,8 +522,15 @@ function extractStaticTranslationKeys(source: string, namespaces: readonly strin
if (rawKey.endsWith(".")) return;
const parsed = parseTranslationKey(rawKey, namespace, namespaceSet);
const key = applyKeyPrefix(parsed.key, rawKey, keyPrefix);
const sourceKey = { key, namespace: parsed.namespace, fallback };
keys.set(`${sourceKey.namespace ?? "*"}:${sourceKey.key}:${sourceKey.fallback}`, sourceKey);
const sourceKey = { key, namespace: parsed.namespace, fallback, family: false };
keys.set(`${sourceKey.namespace ?? "*"}:${sourceKey.key}:${sourceKey.fallback}:exact`, sourceKey);
};
const addFamily = (rawPattern: string, fallback: MissingSourceKeyFallback, namespace: string | null = inferredNamespace, keyPrefix: string | null = inferredKeyPrefix) => {
const parsed = parseTranslationKey(rawPattern, namespace, namespaceSet);
const key = applyKeyPrefix(parsed.key, rawPattern, keyPrefix);
const sourceKey = { key, namespace: parsed.namespace, fallback, family: true };
keys.set(`${sourceKey.namespace ?? "*"}:${sourceKey.key}:${sourceKey.fallback}:family`, sourceKey);
};
for (const match of source.matchAll(/\bt\(\s*["']([A-Za-z0-9_.:-]+)["']([^)]*)\)/g)) {
@@ -328,6 +540,14 @@ function extractStaticTranslationKeys(source: string, namespaces: readonly strin
const keyPrefix = extractOptionKeyPrefix(tail) ?? inferredKeyPrefix;
addKey(rawKey, hasDefaultValueFallback(tail) || localFallbackKeys.has(rawKey) ? "fallback" : "no-fallback", namespace, keyPrefix);
}
for (const match of source.matchAll(/\bt\(\s*`((?:\\.|[^`])*(?:\$\{)(?:\\.|[^`])*)`([^)]*)\)/g)) {
const rawPattern = dynamicTemplateToKeyFamily(match[1]);
if (!rawPattern) continue;
const tail = match[2] ?? "";
const namespace = extractOptionNamespace(tail, namespaceSet) ?? inferredNamespace;
const keyPrefix = extractOptionKeyPrefix(tail) ?? inferredKeyPrefix;
addFamily(rawPattern, hasDefaultValueFallback(tail) ? "fallback" : "no-fallback", namespace, keyPrefix);
}
for (const match of source.matchAll(/\bt\(\s*\(?\s*\$[A-Za-z0-9_]*\s*\)?\s*=>\s*\$[A-Za-z0-9_]*((?:\.[A-Za-z_$][\w$]*)+)([^)]*)\)/g)) {
const rawKey = match[1].slice(1);
const tail = match[2] ?? "";
@@ -338,19 +558,77 @@ function extractStaticTranslationKeys(source: string, namespaces: readonly strin
const index = match.index ?? 0;
addKey(match[1], hasNearbyLiteralFallback(source, index) ? "fallback" : "no-fallback", extractNearbyNamespace(source, index, namespaceSet), extractNearbyKeyPrefix(source, index));
}
for (const match of source.matchAll(/\b(?:labelKey|titleKey|descriptionKey|messageKey)\s*:\s*["']([A-Za-z0-9_.:-]+)["']/g)) {
for (const match of source.matchAll(new RegExp(`\\b(?:${TRANSLATION_KEY_FIELD_PATTERN})\\s*:\\s*["']([A-Za-z0-9_.:-]+)["']`, "g"))) {
addKey(match[1], hasNearbyLiteralFallback(source, match.index ?? 0) ? "fallback" : "no-fallback", null);
}
for (const match of source.matchAll(/\bi18nKey\s*=\s*["']([A-Za-z0-9_.:-]+)["']/g)) {
const index = match.index ?? 0;
addKey(match[1], "no-fallback", extractNearbyNamespace(source, index, namespaceSet), extractNearbyKeyPrefix(source, index));
}
for (const match of source.matchAll(/\b(?:labelKey|titleKey|descriptionKey|messageKey)\s*=\s*["']([A-Za-z0-9_.:-]+)["']/g)) {
for (const match of source.matchAll(new RegExp(`\\b(?:${TRANSLATION_KEY_FIELD_PATTERN})[ \\t]*=[ \\t]*["']([A-Za-z0-9_.:-]+)["']`, "g"))) {
const linePrefix = source.slice(source.lastIndexOf("\n", match.index ?? 0) + 1, match.index ?? 0);
if (/\b(?:const|let|var)\s+$/u.test(linePrefix)) continue;
addKey(match[1], "no-fallback", null);
}
return [...keys.values()].sort((left, right) => `${left.namespace ?? "*"}:${left.key}`.localeCompare(`${right.namespace ?? "*"}:${right.key}`));
}
function dynamicTemplateToKeyFamily(template: string): string | null {
let pattern = "";
let cursor = 0;
let interpolationCount = 0;
while (cursor < template.length) {
const interpolationStart = template.indexOf("${", cursor);
if (interpolationStart < 0) {
pattern += template.slice(cursor);
break;
}
pattern += template.slice(cursor, interpolationStart);
const interpolationEnd = findInterpolationEnd(template, interpolationStart + 2);
if (interpolationEnd < 0) return null;
pattern += "*";
interpolationCount += 1;
cursor = interpolationEnd + 1;
}
const literalPart = pattern.replaceAll("*", "").replaceAll(/[.:-]/g, "");
return interpolationCount > 0 && /[A-Za-z0-9]/u.test(literalPart) ? pattern.replaceAll(/\*+/g, "*") : null;
}
function findInterpolationEnd(template: string, expressionStart: number): number {
let depth = 1;
let quote: "\"" | "'" | null = null;
let escaped = false;
for (let index = expressionStart; index < template.length; index += 1) {
const char = template[index];
if (quote) {
if (escaped) {
escaped = false;
} else if (char === "\\") {
escaped = true;
} else if (char === quote) {
quote = null;
}
continue;
}
if (char === "\"" || char === "'") {
quote = char;
continue;
}
if (char === "{") depth += 1;
if (char === "}") depth -= 1;
if (depth === 0) return index;
}
return -1;
}
function escapeRegExp(value: string) {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function parseTranslationKey(rawKey: string, namespace: string | null, namespaces: Set<string>) {
const separatorIndex = rawKey.indexOf(":");
if (separatorIndex > 0) {
@@ -478,10 +756,17 @@ function formatIssue(issue: LocaleParityIssue): string {
if (issue.type === "empty-translation") {
return [`- empty translation values [${issue.locale}/${issue.namespace}]: ${issue.filePath}`, formatKeyList("keys", issue.keys)].join("\n");
}
if (issue.type === "language-leak") {
return [
`- German UI text in English catalog [${issue.locale}/${issue.namespace}]: ${issue.filePath}`,
...issue.findings.map((finding) => ` - ${finding.key} [${finding.words.join(", ")}]`),
].join("\n");
}
if (issue.type === "unexpected-locale-dir") return `- unexpected locale directory [${issue.locale}]: ${issue.directoryPath}`;
if (issue.type === "missing-source-key") {
const namespace = issue.namespace ? `${issue.namespace}:` : "";
return [`- missing source translation key (${issue.fallback}): ${namespace}${issue.key}`, formatKeyList("files", issue.files)].join("\n");
const kind = issue.key.includes("*") ? "key family" : "key";
return [`- missing source translation ${kind} (${issue.fallback}): ${namespace}${issue.key}`, formatKeyList("files", issue.files)].join("\n");
}
return [