feat(i18n): add internationalization support across multiple components

This commit is contained in:
2025-10-27 14:41:58 +08:00
parent 49742f6219
commit 46cc8a254a
23 changed files with 777 additions and 2623 deletions

View File

@@ -15,6 +15,7 @@ import {
ListSubheader,
} from '@mui/material';
import { useForm, Controller } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { LlmSvgIcon } from '@/components/AppSvgIcon';
import { IconMap, type LLMFactory } from '@/constants/llm';
import type { ITenantInfo } from '@/interfaces/database/knowledge';
@@ -69,6 +70,7 @@ function SystemModelDialog({
editMode = false,
allModelOptions
}: SystemModelDialogProps) {
const { t } = useTranslation();
const { control, handleSubmit, reset, formState: { errors } } = useForm<ITenantInfo>({
defaultValues: {}
});
@@ -106,25 +108,25 @@ function SystemModelDialog({
await onSubmit(data);
onClose();
} catch (error) {
console.error('提交失败:', error);
console.error(t('setting.submitFailed'), error);
}
};
return (
<Dialog open={open} onClose={onClose} maxWidth="sm" fullWidth>
<DialogTitle>
{t('setting.setDefaultModel')}
</DialogTitle>
<DialogContent>
<Box component="form" sx={{ mt: 2 }}>
<Controller
name="llm_id"
control={control}
rules={{ required: '聊天模型是必填项' }}
rules={{ required: t('setting.chatModelRequired') }}
render={({ field }) => (
<FormControl fullWidth margin="normal" error={!!errors.llm_id}>
<InputLabel></InputLabel>
<Select {...field} label="聊天模型">
<InputLabel>{t('setting.chatModel')}</InputLabel>
<Select {...field} label={t('setting.chatModel')}>
{llmOptions.map((group) => [
<ListSubheader key={group.label}>{group.label}</ListSubheader>,
...group.options.map((option) => (
@@ -152,11 +154,11 @@ function SystemModelDialog({
<Controller
name="embd_id"
control={control}
rules={{ required: '嵌入模型是必填项' }}
rules={{ required: t('setting.embeddingModelRequired') }}
render={({ field }) => (
<FormControl fullWidth margin="normal" error={!!errors.embd_id}>
<InputLabel></InputLabel>
<Select {...field} label="嵌入模型">
<InputLabel>{t('setting.embeddingModel')}</InputLabel>
<Select {...field} label={t('setting.embeddingModel')}>
{embdOptions.map((group) => [
<ListSubheader key={group.label}>{group.label}</ListSubheader>,
...group.options.map((option) => (
@@ -186,8 +188,8 @@ function SystemModelDialog({
control={control}
render={({ field }) => (
<FormControl fullWidth margin="normal">
<InputLabel>Img2txt模型</InputLabel>
<Select {...field} label="Img2txt模型">
<InputLabel>{t('setting.img2txtModel')}</InputLabel>
<Select {...field} label={t('setting.img2txtModel')}>
{img2txtOptions.map((group) => [
<ListSubheader key={group.label}>{group.label}</ListSubheader>,
...group.options.map((option) => (
@@ -212,8 +214,8 @@ function SystemModelDialog({
control={control}
render={({ field }) => (
<FormControl fullWidth margin="normal">
<InputLabel>Speech2txt模型</InputLabel>
<Select {...field} label="Speech2txt模型">
<InputLabel>{t('setting.speech2txtModel')}</InputLabel>
<Select {...field} label={t('setting.speech2txtModel')}>
{asrOptions.map((group) => [
<ListSubheader key={group.label}>{group.label}</ListSubheader>,
...group.options.map((option) => (
@@ -238,8 +240,8 @@ function SystemModelDialog({
control={control}
render={({ field }) => (
<FormControl fullWidth margin="normal">
<InputLabel>Rerank模型</InputLabel>
<Select {...field} label="Rerank模型">
<InputLabel>{t('setting.rerankModel')}</InputLabel>
<Select {...field} label={t('setting.rerankModel')}>
{rerankOptions.map((group) => [
<ListSubheader key={group.label}>{group.label}</ListSubheader>,
...group.options.map((option) => (
@@ -264,8 +266,8 @@ function SystemModelDialog({
control={control}
render={({ field }) => (
<FormControl fullWidth margin="normal">
<InputLabel>TTS模型</InputLabel>
<Select {...field} label="TTS模型">
<InputLabel>{t('setting.ttsModel')}</InputLabel>
<Select {...field} label={t('setting.ttsModel')}>
{ttsOptions.map((group) => [
<ListSubheader key={group.label}>{group.label}</ListSubheader>,
...group.options.map((option) => (
@@ -288,7 +290,7 @@ function SystemModelDialog({
</DialogContent>
<DialogActions>
<Button onClick={onClose} disabled={loading}>
{t('setting.cancel')}
</Button>
<Button
onClick={handleSubmit(handleFormSubmit)}
@@ -296,7 +298,7 @@ function SystemModelDialog({
disabled={loading}
startIcon={loading ? <CircularProgress size={20} /> : null}
>
{t('setting.confirm')}
</Button>
</DialogActions>
</Dialog>