From 893d9da3f3ad32c86f68023e5b57290d529c18c1 Mon Sep 17 00:00:00 2001 From: ZhaiSoul <842607283@qq.com> Date: Tue, 12 May 2026 20:36:08 +0800 Subject: [PATCH] fix: fix lpr setting item i18n --- .../theme/fields/KnownPlatesField.tsx | 16 +++++++++--- .../theme/fields/ReplaceRulesField.tsx | 25 +++++++++++++++---- .../theme/templates/ObjectFieldTemplate.tsx | 15 +++++------ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/web/src/components/config-form/theme/fields/KnownPlatesField.tsx b/web/src/components/config-form/theme/fields/KnownPlatesField.tsx index e47c298674..44577ff9f2 100644 --- a/web/src/components/config-form/theme/fields/KnownPlatesField.tsx +++ b/web/src/components/config-form/theme/fields/KnownPlatesField.tsx @@ -28,7 +28,11 @@ export function KnownPlatesField(props: FieldProps) { | ConfigFormContext | undefined; - const { t } = useTranslation(["views/settings", "common"]); + const configNamespace = + formContext?.i18nNamespace ?? + (formContext?.level === "camera" ? "config/cameras" : "config/global"); + const { t: fallbackT } = useTranslation(["common", configNamespace]); + const t = formContext?.t ?? fallbackT; const data: KnownPlatesData = useMemo(() => { if (!formData || typeof formData !== "object" || Array.isArray(formData)) { @@ -39,8 +43,14 @@ export function KnownPlatesField(props: FieldProps) { const entries = useMemo(() => Object.entries(data), [data]); - const title = (schema as RJSFSchema).title; - const description = (schema as RJSFSchema).description; + const id = idSchema?.$id ?? props.name; + const sectionPrefix = formContext?.sectionI18nPrefix; + + const title = + t(`${sectionPrefix}.${id}.label`) ?? (schema as RJSFSchema).title; + const description = + t(`${sectionPrefix}.${id}.description`) ?? + (schema as RJSFSchema).description; const hasItems = entries.length > 0; const emptyPath = useMemo(() => [] as FieldPathList, []); diff --git a/web/src/components/config-form/theme/fields/ReplaceRulesField.tsx b/web/src/components/config-form/theme/fields/ReplaceRulesField.tsx index 08c5c781fb..94fa7098c7 100644 --- a/web/src/components/config-form/theme/fields/ReplaceRulesField.tsx +++ b/web/src/components/config-form/theme/fields/ReplaceRulesField.tsx @@ -47,7 +47,11 @@ export function ReplaceRulesField(props: FieldProps) { | ConfigFormContext | undefined; - const { t } = useTranslation(["common"]); + const configNamespace = + formContext?.i18nNamespace ?? + (formContext?.level === "camera" ? "config/cameras" : "config/global"); + const { t: fallbackT } = useTranslation(["common", configNamespace]); + const t = formContext?.t ?? fallbackT; const rules: ReplaceRule[] = useMemo(() => { if (!Array.isArray(formData)) { @@ -60,10 +64,21 @@ export function ReplaceRulesField(props: FieldProps) { () => getItemSchema(schema as RJSFSchema), [schema], ); - const title = (schema as RJSFSchema).title; - const description = (schema as RJSFSchema).description; - const patternTitle = getPropertyTitle(itemSchema, "pattern"); - const replacementTitle = getPropertyTitle(itemSchema, "replacement"); + + const id = idSchema?.$id ?? props.name; + const sectionPrefix = formContext?.sectionI18nPrefix; + + const title = + t(`${sectionPrefix}.${id}.label`) ?? (schema as RJSFSchema).title; + const description = + t(`${sectionPrefix}.${id}.description`) ?? + (schema as RJSFSchema).description; + const patternTitle = + t(`${sectionPrefix}.${id}.pattern.label`) ?? + getPropertyTitle(itemSchema, "pattern", t); + const replacementTitle = + t(`${sectionPrefix}.${id}.replacement.label`) ?? + getPropertyTitle(itemSchema, "replacement", t); const hasItems = rules.length > 0; const emptyPath = useMemo(() => [] as FieldPathList, []); diff --git a/web/src/components/config-form/theme/templates/ObjectFieldTemplate.tsx b/web/src/components/config-form/theme/templates/ObjectFieldTemplate.tsx index 29cf4c310c..bdd61eb1ff 100644 --- a/web/src/components/config-form/theme/templates/ObjectFieldTemplate.tsx +++ b/web/src/components/config-form/theme/templates/ObjectFieldTemplate.tsx @@ -157,8 +157,9 @@ export function ObjectFieldTemplate(props: ObjectFieldTemplateProps) { const hasModifiedDescendants = checkSubtreeModified(fieldPath); const [isOpen, setIsOpen] = useState(hasModifiedDescendants); - const resetKey = `${formContext?.level ?? "global"}::${formContext?.cameraName ?? "global" - }`; + const resetKey = `${formContext?.level ?? "global"}::${ + formContext?.cameraName ?? "global" + }`; const lastResetKeyRef = useRef(null); // Auto-expand collapsible when modifications are detected @@ -336,12 +337,12 @@ export function ObjectFieldTemplate(props: ObjectFieldTemplateProps) { const label = domain ? t(`${sectionI18nPrefix}.${domain}.${groupKey}`, { - ns: "config/groups", - defaultValue: humanizeKey(groupKey), - }) + ns: "config/groups", + defaultValue: humanizeKey(groupKey), + }) : t(`groups.${groupKey}`, { - defaultValue: humanizeKey(groupKey), - }); + defaultValue: humanizeKey(groupKey), + }); const groupInfo = { groupKey, label, items: ordered }; for (const item of ordered) {