mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-05 22:57:40 +03:00
add optional i18n prefix for select widgets
This commit is contained in:
parent
e7609afb54
commit
5f61c54efd
@ -1,5 +1,6 @@
|
|||||||
// Select Widget - maps to shadcn/ui Select
|
// Select Widget - maps to shadcn/ui Select
|
||||||
import type { WidgetProps } from "@rjsf/utils";
|
import type { WidgetProps } from "@rjsf/utils";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@ -21,9 +22,18 @@ export function SelectWidget(props: WidgetProps) {
|
|||||||
schema,
|
schema,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
const { t } = useTranslation(["views/settings"]);
|
||||||
const { enumOptions = [] } = options;
|
const { enumOptions = [] } = options;
|
||||||
|
const enumI18nPrefix = options["enumI18nPrefix"] as string | undefined;
|
||||||
const fieldClassName = getSizedFieldClassName(options, "sm");
|
const fieldClassName = getSizedFieldClassName(options, "sm");
|
||||||
|
|
||||||
|
const getLabel = (option: { value: unknown; label: string }) => {
|
||||||
|
if (enumI18nPrefix) {
|
||||||
|
return t(`${enumI18nPrefix}.${option.value}`);
|
||||||
|
}
|
||||||
|
return option.label;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
value={value?.toString() ?? ""}
|
value={value?.toString() ?? ""}
|
||||||
@ -42,7 +52,7 @@ export function SelectWidget(props: WidgetProps) {
|
|||||||
<SelectContent>
|
<SelectContent>
|
||||||
{enumOptions.map((option: { value: unknown; label: string }) => (
|
{enumOptions.map((option: { value: unknown; label: string }) => (
|
||||||
<SelectItem key={String(option.value)} value={String(option.value)}>
|
<SelectItem key={String(option.value)} value={String(option.value)}>
|
||||||
{option.label}
|
{getLabel(option)}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user