mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 14:16:12 +00:00
refactor(i18n): ask the catalogue for a sentence in one helper
`t()` answers a missing key with the key, so "does this code have a sentence" was a comparison written inline at every site that wanted a code's sentence or a fallback, twenty-odd times in several spellings. translateOrNull, translateCodeOrNull and translateCode in src/lib/i18n/translate-code.ts now hold that probe, every site uses them, and a guard refuses the inline comparison anywhere else.
This commit is contained in:
1 parent
2f7f04ecab
commit
6e54f33901
32 files changed
+291
-119
No files matched your search
@@ -63,6 +63,7 @@ import type { EncounterDTO } from "@/lib/encounters/dto";
|
||||
import type { IllnessEpisodeDTO } from "@/lib/illness/dto";
|
||||
import type { RelatedLink } from "@/lib/links/related";
|
||||
import type { EncounterKind } from "@/generated/prisma/client";
|
||||
import { translateOrNull } from "@/lib/i18n/translate-code";
|
||||
|
||||
type Translate = ReturnType<typeof useTranslations>["t"];
|
||||
type RelatedKind = RelatedLink["kind"];
|
||||
@@ -114,9 +115,8 @@ function rowLabel(t: Translate, row: RelatedLink): string {
|
||||
// A dose without a written name arrives as its catalogue slug ("tetanus"),
|
||||
// named here from the reader's bundle the way the dose picker names it.
|
||||
if (row.kind === "vaccination" && /^[a-z0-9_-]+$/.test(row.label)) {
|
||||
const key = `vaccinations.catalog.${row.label}`;
|
||||
const name = t(key);
|
||||
if (name !== key) return name;
|
||||
const name = translateOrNull(t, `vaccinations.catalog.${row.label}`);
|
||||
if (name !== null) return name;
|
||||
}
|
||||
return row.label;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user