fix: fix lpr setting item i18n

This commit is contained in:
ZhaiSoul
2026-05-12 20:36:08 +08:00
parent 19dcad7989
commit 893d9da3f3
3 changed files with 41 additions and 15 deletions
@@ -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, []);
@@ -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, []);
@@ -157,7 +157,8 @@ 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<string | null>(null);