feat(i18n): add internationalization support across multiple components
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
PhotoCamera as PhotoCameraIcon,
|
||||
Delete as DeleteIcon,
|
||||
} from '@mui/icons-material';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
interface GeneralFormProps {
|
||||
form?: UseFormReturn;
|
||||
@@ -32,9 +33,13 @@ function GeneralForm({
|
||||
onSubmit,
|
||||
isSubmitting,
|
||||
onCancel,
|
||||
submitButtonText = '保存',
|
||||
cancelButtonText = '取消',
|
||||
submitButtonText,
|
||||
cancelButtonText,
|
||||
}: GeneralFormProps = {}) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const defaultSubmitButtonText = submitButtonText || t('common.save');
|
||||
const defaultCancelButtonText = cancelButtonText || t('common.cancel');
|
||||
// 优先使用props传递的form,否则使用FormProvider的context
|
||||
let contextForm: UseFormReturn | null = null;
|
||||
try {
|
||||
@@ -50,7 +55,7 @@ function GeneralForm({
|
||||
return (
|
||||
<Box sx={{ p: 2, textAlign: 'center' }}>
|
||||
<Typography color="error">
|
||||
表单配置错误:请确保组件在FormProvider中使用或传递form参数
|
||||
{t('form.configurationError')}
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
@@ -85,7 +90,7 @@ function GeneralForm({
|
||||
return (
|
||||
<Box sx={{ p: 3 }}>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
基础信息
|
||||
{t('knowledge.basicInfo')}
|
||||
</Typography>
|
||||
|
||||
<Grid container spacing={3}>
|
||||
@@ -106,7 +111,7 @@ function GeneralForm({
|
||||
startIcon={<PhotoCameraIcon />}
|
||||
onClick={handleAvatarClick}
|
||||
>
|
||||
上传头像
|
||||
{t('knowledge.uploadAvatar')}
|
||||
</Button>
|
||||
{avatar && (
|
||||
<IconButton
|
||||
@@ -136,11 +141,11 @@ function GeneralForm({
|
||||
<Controller
|
||||
name="name"
|
||||
control={control}
|
||||
rules={{ required: '知识库名称不能为空' }}
|
||||
rules={{ required: t('knowledge.nameRequired') }}
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<TextField
|
||||
{...field}
|
||||
label="知识库名称"
|
||||
label={t('knowledge.knowledgeBaseName')}
|
||||
fullWidth
|
||||
required
|
||||
error={!!error}
|
||||
@@ -157,11 +162,11 @@ function GeneralForm({
|
||||
render={({ field }) => (
|
||||
<TextField
|
||||
{...field}
|
||||
label="描述"
|
||||
label={t('common.description')}
|
||||
fullWidth
|
||||
multiline
|
||||
rows={3}
|
||||
placeholder="请输入知识库描述..."
|
||||
placeholder={t('knowledge.descriptionPlaceholder')}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
@@ -173,10 +178,10 @@ function GeneralForm({
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<FormControl fullWidth>
|
||||
<InputLabel>权限设置</InputLabel>
|
||||
<Select {...field} label="权限设置">
|
||||
<MenuItem value="me">仅自己</MenuItem>
|
||||
<MenuItem value="team">团队成员</MenuItem>
|
||||
<InputLabel>{t('knowledge.permissionSettings')}</InputLabel>
|
||||
<Select {...field} label={t('knowledge.permissionSettings')}>
|
||||
<MenuItem value="me">{t('knowledge.onlyMe')}</MenuItem>
|
||||
<MenuItem value="team">{t('knowledge.teamMembers')}</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
@@ -195,7 +200,7 @@ function GeneralForm({
|
||||
onClick={onCancel}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{cancelButtonText}
|
||||
{defaultCancelButtonText}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
@@ -203,7 +208,7 @@ function GeneralForm({
|
||||
onClick={form ? form.handleSubmit(onSubmit) : undefined}
|
||||
disabled={isSubmitting || !form}
|
||||
>
|
||||
{isSubmitting ? '提交中...' : submitButtonText}
|
||||
{isSubmitting ? t('common.submitting') : defaultSubmitButtonText}
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user