mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 06:40:50 +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
@@ -89,6 +89,7 @@ import {
|
||||
DEFAULT_CHART_RANGE,
|
||||
rangeWindowDays,
|
||||
} from "./chart-range-tabs";
|
||||
import { translateOrNull } from "@/lib/i18n/translate-code";
|
||||
|
||||
// The range tabs (7 / 30 / 90 / All, a calendar-day window ending now) and
|
||||
// the "All" tab's ten-year fetch span live with the shared
|
||||
@@ -399,8 +400,7 @@ function getTypeLabel(
|
||||
const key = BASE_TYPE_LABEL_KEYS[type];
|
||||
if (key) return t(key);
|
||||
const measurementKey = measurementLabelKey(type);
|
||||
const label = t(measurementKey);
|
||||
return label === measurementKey ? type : label;
|
||||
return translateOrNull(t, measurementKey) ?? type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user