mirror of
https://github.com/bitbaum/evig.git
synced 2026-12-04 05:37:00 +01:00
* chore: add a formatter, matching the style this repo already writes singleQuote=true was chosen by counting this repo's own imports, not by fleet decree. The fleet is genuinely split and the two repos that already had a .prettierrc disagreed with each other, so there was no standard to restore. Quote style does not cross repo boundaries; having a gate does. Markdown is ignored for now — prettier rewraps prose, which would bury the real diff. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * style: format with prettier, and close a comment that was never closed The formatter refused this repo outright, which turned out to be a real defect rather than a tooling complaint. kivitendo-intake.css opens a header comment, and line 17 contains an inner /* ⚠ PRÜFEN */ — CSS comments do not nest, so that inner terminator CLOSES the header. Everything after it is parsed as CSS until the stray */ on line 20. A browser mis-parses it the same way. The file exists in two places (public/presentations/ and deliverables/), both carrying the same defect; fixing one still failed the gate, which is how the duplicate surfaced at all. Mechanical otherwise. This SHA is listed in .git-blame-ignore-revs. * chore: teach git blame to skip the reformat * fix: undo a 3-way merge duplication in AdminSidebar.tsx Merging main with -X theirs duplicated a 30-line block: main's currency-sweep commit and this branch's prettier reformat both touched overlapping lines in the single-destination-group render path, and the -X theirs strategy inserted rather than replaced, leaving two near-identical copies and a dangling closing brace — SyntaxError: ',' expected at line 298. The branch has no legitimate change to this file's logic, only formatting, so main's content is correct outright. Took it wholesale rather than hand-editing the merge result. * fix(lint): reattach 5 directives the reformat detached Four eslint-disable-next-line sites for react-hooks/set-state-in-effect and one @ts-expect-error, all the same defect: the directive sat above useEffect( (or above a JSX element), while the statement that actually errors is 1-2 lines further down inside the block. eslint/tsc report at the real statement; the directive, still bound to its original line number, protects nothing there. TimecardReviewDrawer.tsx (x2), DataEntryTabs.tsx, AppointmentBookingForm.tsx, CreatePoolModal.tsx. Same root cause documented for hirnli, fleetcrown and ivy-portal earlier today — a positional directive is a hidden dependency on formatting, and this is the fourth distinct shape it's taken. * fix(i18n): restore a same-line audit-exemption marker Fifth shape of today's positional-directive defect, this time the repo's own i18n-hardcoded-audit convention rather than eslint or tsc: a // i18n-ok comment exempts a hardcoded string only when it trails the SAME line. prettier wrapped this one if-statement's long condition onto its own line, leaving the marker on the return statement below — the exact sibling one line down ('fortgeschrittene bis experten') stayed on one line because it was short enough not to wrap, and it alone kept passing. Restored the one-line form and added // prettier-ignore so a future reformat cannot re-split it. Verified against the real audit script locally: 0 new violations. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
135 lines
4.5 KiB
JavaScript
135 lines
4.5 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Merge filled-in translator output back into messages/<locale>.json.
|
|
*
|
|
* Companion to scripts/i18n-missing.mjs. Workflow:
|
|
*
|
|
* 1. npm run i18n:missing
|
|
* → emits messages/_missing/<locale>.json ({ key: { de, translation: null } })
|
|
*
|
|
* 2. Send to translator. They fill in every `translation` field.
|
|
*
|
|
* 3. npm run i18n:apply <locale>
|
|
* → reads messages/_missing/<locale>.json
|
|
* → for every entry with a non-empty translation, sets the matching
|
|
* dotted-key path in messages/<locale>.json
|
|
* → leaves untouched-keys alone (so partial returns are fine)
|
|
*
|
|
* Safe by design:
|
|
* - Never overwrites an existing non-empty value (translator can't
|
|
* accidentally regress strings already translated).
|
|
* - Skips entries where `translation` is null / empty / whitespace.
|
|
* - Prints a summary of applied / skipped / conflicts.
|
|
*/
|
|
|
|
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
import { join, dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const ROOT = join(__dirname, '..');
|
|
const MESSAGES_DIR = join(ROOT, 'messages');
|
|
const VALID_LOCALES = ['en', 'fr', 'es', 'it', 'ja', 'ko', 'ru'];
|
|
|
|
const locale = process.argv[2];
|
|
|
|
if (!locale || !VALID_LOCALES.includes(locale)) {
|
|
console.error(`Usage: npm run i18n:apply <locale>`);
|
|
console.error(` locale must be one of: ${VALID_LOCALES.join(', ')}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const inputPath = join(MESSAGES_DIR, '_missing', `${locale}.json`);
|
|
const targetPath = join(MESSAGES_DIR, `${locale}.json`);
|
|
|
|
if (!existsSync(inputPath)) {
|
|
console.error(`Missing input: ${inputPath}`);
|
|
console.error(`Run \`npm run i18n:missing\` first, then send the file to a translator.`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const input = JSON.parse(readFileSync(inputPath, 'utf8'));
|
|
const target = JSON.parse(readFileSync(targetPath, 'utf8'));
|
|
|
|
function setByPath(obj, dottedPath, value) {
|
|
const parts = dottedPath.split('.');
|
|
let cur = obj;
|
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
const k = parts[i];
|
|
if (cur[k] == null || typeof cur[k] !== 'object' || Array.isArray(cur[k])) {
|
|
cur[k] = {};
|
|
}
|
|
cur = cur[k];
|
|
}
|
|
cur[parts[parts.length - 1]] = value;
|
|
}
|
|
|
|
function getByPath(obj, dottedPath) {
|
|
const parts = dottedPath.split('.');
|
|
let cur = obj;
|
|
for (const k of parts) {
|
|
if (cur == null || typeof cur !== 'object') return undefined;
|
|
cur = cur[k];
|
|
}
|
|
return cur;
|
|
}
|
|
|
|
let applied = 0;
|
|
let skippedEmpty = 0;
|
|
let skippedExisting = 0;
|
|
const conflicts = [];
|
|
|
|
function isEmpty(v) {
|
|
if (v == null) return true;
|
|
if (typeof v === 'string') return v.trim() === '';
|
|
if (Array.isArray(v)) return v.length === 0;
|
|
if (typeof v === 'object') return Object.keys(v).length === 0;
|
|
return false;
|
|
}
|
|
|
|
for (const [key, entry] of Object.entries(input)) {
|
|
// Accept strings, arrays, or objects — the DE source may be any of these
|
|
// (e.g. arrays of feature bullets, arrays of step objects).
|
|
let translation = entry?.translation;
|
|
if (typeof translation === 'string') translation = translation.trim();
|
|
if (isEmpty(translation)) {
|
|
skippedEmpty++;
|
|
continue;
|
|
}
|
|
|
|
const existing = getByPath(target, key);
|
|
// Conflict detection only applies to existing non-empty string values that
|
|
// differ from both DE and the new candidate. Arrays/objects always overwrite
|
|
// (they're either missing or stale — translator owns the structure).
|
|
if (typeof existing === 'string' && existing !== '' && existing !== entry.de) {
|
|
if (existing !== translation) {
|
|
conflicts.push({ key, existing, candidate: translation });
|
|
continue;
|
|
}
|
|
skippedExisting++;
|
|
continue;
|
|
}
|
|
|
|
setByPath(target, key, translation);
|
|
applied++;
|
|
}
|
|
|
|
writeFileSync(targetPath, JSON.stringify(target, null, 2) + '\n', 'utf8');
|
|
|
|
console.log(`\n ${locale}:`);
|
|
console.log(` Applied: ${applied}`);
|
|
console.log(` Skipped (empty): ${skippedEmpty}`);
|
|
console.log(` Skipped (already translated): ${skippedExisting}`);
|
|
if (conflicts.length) {
|
|
console.log(` CONFLICTS (manual review needed): ${conflicts.length}`);
|
|
for (const c of conflicts.slice(0, 10)) {
|
|
console.log(` ${c.key}`);
|
|
console.log(` existing : ${c.existing}`);
|
|
console.log(` candidate : ${c.candidate}`);
|
|
}
|
|
if (conflicts.length > 10) console.log(` ... and ${conflicts.length - 10} more`);
|
|
}
|
|
console.log();
|
|
console.log(` Wrote: ${targetPath.replace(ROOT + '/', '')}`);
|
|
console.log(` Re-run \`npm run i18n:missing\` to verify the missing count dropped.`);
|