feat(i18n): add internationalization support across multiple components

This commit is contained in:
2025-10-29 16:40:20 +08:00
parent 184c232cc8
commit 9199ed7c29
34 changed files with 1455 additions and 761 deletions

View File

@@ -9,6 +9,7 @@ import {
InputLabel,
} from '@mui/material';
import { Controller, useFormContext } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
export interface SelectOption {
value: string | number;
@@ -42,10 +43,13 @@ export const SelectFormField: React.FC<SelectFormFieldProps> = ({
fullWidth = true,
size = 'medium',
displayEmpty = true,
emptyLabel = '请选择',
emptyLabel,
multiple = false,
}) => {
const { control } = useFormContext();
const { t } = useTranslation();
const defaultEmptyLabel = emptyLabel || t('common.pleaseSelect');
return (
<Box>
@@ -58,7 +62,7 @@ export const SelectFormField: React.FC<SelectFormFieldProps> = ({
control={control}
defaultValue={multiple ? [] : defaultValue}
rules={{
required: required ? `${label}是必填项` : false,
required: required ? t('form.fieldRequired', { field: label }) : false,
}}
render={({ field, fieldState: { error } }) => (
<FormControl fullWidth={fullWidth} error={!!error} size={size}>
@@ -70,7 +74,7 @@ export const SelectFormField: React.FC<SelectFormFieldProps> = ({
>
{displayEmpty && !multiple && (
<MenuItem value="">
{emptyLabel}
{defaultEmptyLabel}
</MenuItem>
)}
{options.map((option) => (