Files
yourpart3/frontend/scripts/check-i18n-locale-parity.mjs
Torsten Schulz (local) f7030bbabe
All checks were successful
Deploy to production / deploy (push) Successful in 2m48s
feat(i18n): add French language support and enhance localization
- Introduced French as a supported language across the application, updating locale files and adding translations for various components.
- Enhanced language handling logic to accommodate French, ensuring proper detection and fallback mechanisms.
- Updated UI elements to include French language options, improving accessibility for French-speaking users.
- Refactored SEO handling to include French in hreflang links, enhancing search engine indexing for multilingual content.
- Added new scripts for managing French translations and ensuring consistency across language files.
2026-04-07 18:04:03 +02:00

79 lines
2.0 KiB
JavaScript

/**
* Vergleicht flache Schlüsselpfade zwischen zwei Locale-Ordnern (gleiche JSON-Dateinamen).
*
* Aufruf: node scripts/check-i18n-locale-parity.mjs de fr
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const BASE = path.join(__dirname, '../src/i18n/locales');
function flattenLeaves(obj, prefix = '', out = {}) {
if (obj === null || typeof obj !== 'object' || Array.isArray(obj)) {
out[prefix] = obj;
return out;
}
const keys = Object.keys(obj);
if (keys.length === 0) {
out[prefix] = obj;
return out;
}
for (const k of keys) {
const p = prefix ? `${prefix}.${k}` : k;
const v = obj[k];
if (v !== null && typeof v === 'object' && !Array.isArray(v)) {
flattenLeaves(v, p, out);
} else {
out[p] = v;
}
}
return out;
}
const [a, b] = process.argv.slice(2);
if (!a || !b) {
console.error('Usage: node scripts/check-i18n-locale-parity.mjs <localeA> <localeB>');
process.exit(2);
}
const dirA = path.join(BASE, a);
const dirB = path.join(BASE, b);
const files = fs.readdirSync(dirA).filter((f) => f.endsWith('.json'));
let errors = 0;
for (const f of files) {
const pa = path.join(dirA, f);
const pb = path.join(dirB, f);
if (!fs.existsSync(pb)) {
console.error(`Fehlt: ${b}/${f}`);
errors++;
continue;
}
const ja = JSON.parse(fs.readFileSync(pa, 'utf8'));
const jb = JSON.parse(fs.readFileSync(pb, 'utf8'));
const fa = flattenLeaves(ja);
const fb = flattenLeaves(jb);
const ka = new Set(Object.keys(fa));
const kb = new Set(Object.keys(fb));
for (const k of ka) {
if (!kb.has(k)) {
console.error(`[${f}] fehlt in ${b}: ${k}`);
errors++;
}
}
for (const k of kb) {
if (!ka.has(k)) {
console.error(`[${f}] extra in ${b}: ${k}`);
errors++;
}
}
}
if (errors) {
console.error(`\n${errors} Abweichung(en).`);
process.exit(1);
}
console.log(`OK: Key-Parität ${a}${b} für ${files.length} Dateien.`);