All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 45s
- Implemented `fill-de-extended-gaps.js` to fill missing billing/orders keys in de-extended from de. - Created `fill-i18n-deep.py` for deep translation of locale JSONs using deep-translator with fallback options. - Added `fill-i18n-locales.js` to translate locale JSONs and write overrides for untranslated keys. - Introduced `fix-en-leaks.py` to translate keys that still match the en-US merge, addressing English leaks. - Developed `patch-de-ch-swiss.js` to replace 'ß' with 'ss' in de-CH.json without deleting existing entries. - Created `patch-en-gb-au.js` to apply UK/AU spelling corrections in en-GB and en-AU locales. - Added shell scripts `run-fix-en-leaks.sh` and `run-i18n-deep-fill.sh` for sequential execution of translation tasks. - Implemented `update-i18n-todo-stats.js` to update statistics in the I18N_TODO.md file based on translation completeness.
66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/** Ergänzt fehlende billing/orders-Keys in de-extended aus de. */
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const LOCALES_DIR = path.join(__dirname, '../frontend/src/i18n/locales');
|
|
|
|
function flatten(obj, prefix = '', out = {}) {
|
|
for (const [key, value] of Object.entries(obj || {})) {
|
|
const nextKey = prefix ? `${prefix}.${key}` : key;
|
|
if (value && typeof value === 'object' && !Array.isArray(value)) flatten(value, nextKey, out);
|
|
else if (typeof value === 'string') out[nextKey] = value;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function deepMerge(base, override) {
|
|
if (!base || typeof base !== 'object' || Array.isArray(base)) return override ?? base;
|
|
const result = { ...base };
|
|
for (const [key, value] of Object.entries(override || {})) {
|
|
if (
|
|
value && typeof value === 'object' && !Array.isArray(value) &&
|
|
result[key] && typeof result[key] === 'object' && !Array.isArray(result[key])
|
|
) {
|
|
result[key] = deepMerge(result[key], value);
|
|
} else {
|
|
result[key] = value;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function setByPath(obj, dotPath, value) {
|
|
const parts = dotPath.split('.');
|
|
let cur = obj;
|
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
if (!cur[parts[i]] || typeof cur[parts[i]] !== 'object') cur[parts[i]] = {};
|
|
cur = cur[parts[i]];
|
|
}
|
|
cur[parts[parts.length - 1]] = value;
|
|
}
|
|
|
|
const de = JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, 'de.json'), 'utf8'));
|
|
const ext = JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, 'de-extended.json'), 'utf8'));
|
|
const deFlat = flatten(de);
|
|
const merged = flatten(deepMerge(JSON.parse(JSON.stringify(de)), ext));
|
|
|
|
const NAMESPACES = ['billing', 'orders'];
|
|
let added = 0;
|
|
for (const key of Object.keys(deFlat)) {
|
|
if (!NAMESPACES.some((ns) => key.startsWith(`${ns}.`))) continue;
|
|
if (!(key in flatten(ext)) || merged[key] === deFlat[key]) {
|
|
setByPath(ext, key, deFlat[key]);
|
|
merged[key] = deFlat[key];
|
|
added++;
|
|
}
|
|
}
|
|
|
|
fs.writeFileSync(
|
|
path.join(LOCALES_DIR, 'de-extended.json'),
|
|
`${JSON.stringify(ext, null, 2)}\n`,
|
|
'utf8'
|
|
);
|
|
const stillDe = Object.keys(deFlat).filter((k) => merged[k] === deFlat[k]).length;
|
|
console.log(`de-extended: added ${added} keys, stillDe=${stillDe}`);
|