mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
feat(dashboard): reach shared records from the account switcher, not a card
The "looking after" block sat directly under the greeting and above this account's own day, permanently, for anyone with a single shared record. The dashboard is this account's day; other people's records are a destination, and the account switcher in the top bar and the sidebar already is that door — with the same access level and record kind on each entry. Drop the card, its test, and the five strings only it used, across all six locales. The access-payload consumer guard named that one component as the reader of `level` / `sections` / `recordKind`, so it went red on the deletion, which is what it is for. It now names the surfaces that actually adopt those fields — the presentation resolver and the switcher — and matches the property access rather than one variable name, so a rename of the binding cannot make it match nothing and pass. Verified by removing every reader: it fails. Adds `scripts/i18n-key-tool.mjs` for dropping or rewriting a key across all six bundles in one go.
This commit is contained in:
1 parent
5445bfc1f1
commit
ce9b2814e6
11 files changed
+116
-434
No files matched your search
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* One-shot helper for a text sweep across the six locale bundles.
|
||||
*
|
||||
* node scripts/i18n-key-tool.mjs drop <dotted.key> [...]
|
||||
* node scripts/i18n-key-tool.mjs set <locale> <dotted.key> <value>
|
||||
* node scripts/i18n-key-tool.mjs show <dotted.key>
|
||||
*
|
||||
* Keys are dotted paths into the bundle; a segment containing a literal dot
|
||||
* is not supported (no such key exists). `drop` removes the key from every
|
||||
* locale and prunes an object left empty behind it.
|
||||
*/
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
|
||||
const LOCALES = ["de", "en", "es", "fr", "it", "pl"];
|
||||
const file = (loc) => `messages/${loc}.json`;
|
||||
|
||||
function read(loc) {
|
||||
return JSON.parse(readFileSync(file(loc), "utf8"));
|
||||
}
|
||||
function write(loc, data) {
|
||||
writeFileSync(file(loc), `${JSON.stringify(data, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
function drop(bundle, path) {
|
||||
const parts = path.split(".");
|
||||
const last = parts.pop();
|
||||
const chain = [];
|
||||
let node = bundle;
|
||||
for (const part of parts) {
|
||||
if (node == null || typeof node !== "object") return false;
|
||||
chain.push([node, part]);
|
||||
node = node[part];
|
||||
}
|
||||
if (node == null || !(last in node)) return false;
|
||||
delete node[last];
|
||||
for (let i = chain.length - 1; i >= 0; i -= 1) {
|
||||
const [parent, key] = chain[i];
|
||||
if (parent[key] && Object.keys(parent[key]).length === 0)
|
||||
delete parent[key];
|
||||
else break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function set(bundle, path, value) {
|
||||
const parts = path.split(".");
|
||||
const last = parts.pop();
|
||||
let node = bundle;
|
||||
for (const part of parts) {
|
||||
if (typeof node[part] !== "object" || node[part] === null) node[part] = {};
|
||||
node = node[part];
|
||||
}
|
||||
node[last] = value;
|
||||
}
|
||||
|
||||
function get(bundle, path) {
|
||||
return path.split(".").reduce((n, p) => (n == null ? n : n[p]), bundle);
|
||||
}
|
||||
|
||||
const [cmd, ...rest] = process.argv.slice(2);
|
||||
|
||||
if (cmd === "drop") {
|
||||
for (const loc of LOCALES) {
|
||||
const bundle = read(loc);
|
||||
let n = 0;
|
||||
for (const key of rest) if (drop(bundle, key)) n += 1;
|
||||
write(loc, bundle);
|
||||
console.log(`${loc}: dropped ${n}/${rest.length}`);
|
||||
}
|
||||
} else if (cmd === "set") {
|
||||
const [loc, key, ...valueParts] = rest;
|
||||
const bundle = read(loc);
|
||||
set(bundle, key, valueParts.join(" "));
|
||||
write(loc, bundle);
|
||||
console.log(`${loc}: ${key} set`);
|
||||
} else if (cmd === "show") {
|
||||
for (const loc of LOCALES) {
|
||||
console.log(`${loc}\t${JSON.stringify(get(read(loc), rest[0]))}`);
|
||||
}
|
||||
} else {
|
||||
console.error("usage: drop|set|show");
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in new issue
Block a user