mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-15 00:11:15 +03:00
fix: fix genai runtime_options i18n
This commit is contained in:
parent
b6bdf65c18
commit
4b15e68b74
@ -3,6 +3,8 @@ import yaml from "js-yaml";
|
|||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
import { ConfigFormContext } from "@/types/configForm";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
function formatYaml(value: unknown): string {
|
function formatYaml(value: unknown): string {
|
||||||
if (
|
if (
|
||||||
@ -45,8 +47,14 @@ function parseYaml(text: string): {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function DictAsYamlField(props: FieldProps) {
|
export function DictAsYamlField(props: FieldProps) {
|
||||||
const { formData, onChange, readonly, disabled, idSchema, schema } = props;
|
const { formData, onChange, readonly, disabled, idSchema, schema, registry } =
|
||||||
|
props;
|
||||||
|
const formContext = registry.formContext as ConfigFormContext | undefined;
|
||||||
|
const configNamespace =
|
||||||
|
formContext?.i18nNamespace ??
|
||||||
|
(formContext?.level === "camera" ? "config/cameras" : "config/global");
|
||||||
|
const { t: fallbackT } = useTranslation(["common", configNamespace]);
|
||||||
|
const t = formContext?.t ?? fallbackT;
|
||||||
const emptyPath = useMemo(() => [] as FieldPathList, []);
|
const emptyPath = useMemo(() => [] as FieldPathList, []);
|
||||||
const fieldPath =
|
const fieldPath =
|
||||||
(props as { fieldPathId?: { path?: FieldPathList } }).fieldPathId?.path ??
|
(props as { fieldPathId?: { path?: FieldPathList } }).fieldPathId?.path ??
|
||||||
@ -94,12 +102,16 @@ export function DictAsYamlField(props: FieldProps) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const id = idSchema?.$id ?? props.name;
|
const id = idSchema?.$id ?? props.name;
|
||||||
|
const sectionPrefix = formContext?.sectionI18nPrefix;
|
||||||
|
|
||||||
|
const title = t(`${sectionPrefix}.${id}.label`) ?? schema.title;
|
||||||
|
const description =
|
||||||
|
t(`${sectionPrefix}.${id}.description`) ?? schema.description;
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
{schema.title && (
|
{title && (
|
||||||
<label htmlFor={id} className="text-sm font-medium">
|
<label htmlFor={id} className="text-sm font-medium">
|
||||||
{schema.title}
|
{title}
|
||||||
</label>
|
</label>
|
||||||
)}
|
)}
|
||||||
<Textarea
|
<Textarea
|
||||||
@ -114,8 +126,8 @@ export function DictAsYamlField(props: FieldProps) {
|
|||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
/>
|
/>
|
||||||
{error && <p className="text-xs text-destructive">{error}</p>}
|
{error && <p className="text-xs text-destructive">{error}</p>}
|
||||||
{schema.description && (
|
{description && (
|
||||||
<p className="text-xs text-muted-foreground">{schema.description}</p>
|
<p className="text-xs text-muted-foreground">{description}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user