fix(web): localize flexible-field labels to the active locale (sv/en)
CI / web (push) Has been cancelled
CI / web (push) Has been cancelled
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,7 @@ function Field({
|
||||
}
|
||||
|
||||
export function ObjectDetail() {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const { id } = useParams();
|
||||
const { data: object, isLoading, isError } = useObject(id!);
|
||||
const { data: definitions } = useFieldDefinitions();
|
||||
@@ -40,8 +40,15 @@ export function ObjectDetail() {
|
||||
|
||||
if (!object) return <p className="p-4 text-sm text-neutral-500">{t("objects.notFound")}</p>;
|
||||
|
||||
const labelFor = (key: string) =>
|
||||
definitions?.find((d) => d.key === key)?.labels.find((l) => l.lang === "en")?.label ?? key;
|
||||
// Prefer the active locale's label, then English, then the raw key.
|
||||
const lang = i18n.language.startsWith("sv") ? "sv" : "en";
|
||||
const labelFor = (key: string) => {
|
||||
const labels = definitions?.find((d) => d.key === key)?.labels;
|
||||
const byLang = labels?.find((l) => l.lang === lang)?.label;
|
||||
const byEnglish = labels?.find((l) => l.lang === "en")?.label;
|
||||
|
||||
return byLang ?? byEnglish ?? key;
|
||||
};
|
||||
|
||||
const flexible = Object.entries(object.fields as Record<string, unknown>);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user