Files
trainingstagebuch/scripts/fill-de-extended-gaps.js
Torsten Schulz (local) 5357dac9e1
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 54s
chore: update file permissions for multiple files and add migration for club fee rules
- Changed file permissions from 644 to 755 for various files in the mobile-app and mobile-app_legacy_rn_expo directories, ensuring executable permissions where necessary.
- Added a new SQL migration script to the backend to introduce missing columns for club billing and invoice settings in the clubs table, maintaining synchronization with the current Sequelize model.
2026-07-17 11:51:24 +02:00

66 lines
2.2 KiB
JavaScript
Executable File

#!/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}`);