Files
HealthLog/src/lib/i18n/resolve-key.ts
T
Marc-André Bombeck 9445d89b76 refactor(api,tz): one typed client for every call and one home for wall-clock math
A typed apiFetch wrapper owns the envelope unwrap, the ok-check and the
error read for every client call — two hundred call sites across the
app migrate onto it and a lint rule keeps raw api fetches out for good.
The legacy timezone helpers fold into the tz module and test fixtures
drop personal names.
2026-06-11 02:19:27 +02:00

27 lines
945 B
TypeScript

/**
* Resolve a dotted key (`nav.dashboard`) inside a flat-or-nested
* message object. Returns `undefined` when the key path doesn't land
* on a string leaf so the caller can chain a fallback bundle (English,
* raw key) without ambiguity.
*
* Lives in its own module (no message-bundle imports) so the client
* provider can use it without pulling every locale JSON into the
* client chunk — `shared-resolve.ts` keeps the full bundle map for
* server-side callers and re-exports this helper.
*/
export function resolveKey(
messages: Record<string, unknown>,
key: string,
): string | undefined {
const parts = key.split(".");
let current: unknown = messages;
for (const part of parts) {
if (current && typeof current === "object" && part in current) {
current = (current as Record<string, unknown>)[part];
} else {
return undefined;
}
}
return typeof current === "string" ? current : undefined;
}