Skip to content

Commit 0a85d8d

Browse files
authored
fix: support collection lang (#1437)
1 parent d456553 commit 0a85d8d

File tree

5 files changed

+72
-27
lines changed

5 files changed

+72
-27
lines changed

web/src/app/workspace/collections/collection-form.tsx

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { ModelSpec } from '@/api';
3+
import { ModelSpec, TitleGenerateRequestLanguageEnum } from '@/api';
44
import { useCollectionContext } from '@/components/providers/collection-provider';
55
import { Badge } from '@/components/ui/badge';
66
import { Button } from '@/components/ui/button';
@@ -20,6 +20,8 @@ import {
2020
FormLabel,
2121
} from '@/components/ui/form';
2222
import { Input } from '@/components/ui/input';
23+
import { Label } from '@/components/ui/label';
24+
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
2325
import {
2426
Select,
2527
SelectContent,
@@ -36,7 +38,7 @@ import { apiClient } from '@/lib/api/client';
3638
import { cn, objectKeys } from '@/lib/utils';
3739
import { zodResolver } from '@hookform/resolvers/zod';
3840
import _ from 'lodash';
39-
import { useTranslations } from 'next-intl';
41+
import { useLocale, useTranslations } from 'next-intl';
4042
import Link from 'next/link';
4143
import { useRouter } from 'next/navigation';
4244
import { useCallback, useEffect, useState } from 'react';
@@ -66,6 +68,7 @@ const collectionSchema = z
6668
enable_vision: z.boolean(),
6769
completion: collectionModelSchema,
6870
embedding: collectionModelSchema,
71+
language: z.enum(Object.values(TitleGenerateRequestLanguageEnum)),
6972
}),
7073
})
7174
.refine(
@@ -97,30 +100,6 @@ const collectionSchema = z
97100

98101
type FormValueType = z.infer<typeof collectionSchema>;
99102

100-
const defaultValues: FormValueType = {
101-
title: '',
102-
description: '',
103-
type: 'document',
104-
config: {
105-
source: 'system',
106-
enable_fulltext: true,
107-
enable_knowledge_graph: true,
108-
enable_vector: true,
109-
enable_summary: false,
110-
enable_vision: false,
111-
completion: {
112-
custom_llm_provider: '',
113-
model: '',
114-
model_service_provider: '',
115-
},
116-
embedding: {
117-
custom_llm_provider: '',
118-
model: '',
119-
model_service_provider: '',
120-
},
121-
},
122-
};
123-
124103
export type ProviderModel = {
125104
label?: string;
126105
name?: string;
@@ -136,6 +115,32 @@ export const CollectionForm = ({ action }: { action: 'add' | 'edit' }) => {
136115
const common_tips = useTranslations('common.tips');
137116
const common_action = useTranslations('common.action');
138117
const page_collections = useTranslations('page_collections');
118+
const locale = useLocale();
119+
120+
const defaultValues: FormValueType = {
121+
title: '',
122+
description: '',
123+
type: 'document',
124+
config: {
125+
source: 'system',
126+
enable_fulltext: true,
127+
enable_knowledge_graph: true,
128+
enable_vector: true,
129+
enable_summary: false,
130+
enable_vision: false,
131+
completion: {
132+
custom_llm_provider: '',
133+
model: '',
134+
model_service_provider: '',
135+
},
136+
embedding: {
137+
custom_llm_provider: '',
138+
model: '',
139+
model_service_provider: '',
140+
},
141+
language: locale,
142+
},
143+
};
139144

140145
const CollectionConfigIndexTypes = {
141146
'config.enable_vector': {
@@ -372,6 +377,32 @@ export const CollectionForm = ({ action }: { action: 'add' | 'edit' }) => {
372377
</FormItem>
373378
)}
374379
/>
380+
381+
<FormField
382+
control={form.control}
383+
name="config.language"
384+
render={({ field }) => (
385+
<FormItem>
386+
<FormLabel>{page_collections('language')}</FormLabel>
387+
<FormControl>
388+
<RadioGroup
389+
value={field.value}
390+
onValueChange={field.onChange}
391+
className="mt-2 flex flex-row gap-4 items-center"
392+
>
393+
<Label>
394+
<RadioGroupItem value="zh-CN" />
395+
{page_collections('language_zh_CN')}
396+
</Label>
397+
<Label>
398+
<RadioGroupItem value="en-US" />
399+
{page_collections('language_en_US')}
400+
</Label>
401+
</RadioGroup>
402+
</FormControl>
403+
</FormItem>
404+
)}
405+
/>
375406
</CardContent>
376407
</Card>
377408

web/src/i18n/en-US.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@
243243
"unpublish_collection_description": "Remove the collection from the marketplace, making it private.",
244244
"name": "Name",
245245
"name_placeholder": "Collection display name.",
246+
"language": "Language",
247+
"language_zh_CN": "Simplified chinese",
248+
"language_en_US": "English",
246249
"description": "Description",
247250
"description_placeholder": "Please describe the general meaning of a collection.",
248251
"index_types": "Index Types",
@@ -401,7 +404,7 @@
401404
"delete": "Delete",
402405
"delete_confirm": "This action cannot be undone. This will permanently delete provider and remove your data from our servers.",
403406
"publish": "Publish to Public",
404-
"publish_confirm": "Confirm publishing this provider to public? This action is irreversible and the provider will be visible to all users.",
407+
"publish_confirm": "Confirm publishing this provider to public? This action is irreversible and the provider will be visible to all admins.",
405408
"publish_success": "Provider published successfully"
406409
},
407410
"model": {

web/src/i18n/en-US/page_collections.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
"name": "Name",
3434
"name_placeholder": "Collection display name.",
3535

36+
"language": "Language",
37+
"language_zh_CN": "Simplified chinese",
38+
"language_en_US": "English",
39+
3640
"description": "Description",
3741
"description_placeholder": "Please describe the general meaning of a collection.",
3842

web/src/i18n/zh-CN.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@
243243
"unpublished_success": "已从市场下架",
244244
"name": "名称",
245245
"name_placeholder": "知识库显示名称",
246+
"language": "大模型语言",
247+
"language_zh_CN": "中文",
248+
"language_en_US": "英文",
246249
"description": "描述",
247250
"description_placeholder": "请简要描述该知识库的整体内容",
248251
"index_types": "索引类型",

web/src/i18n/zh-CN/page_collections.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
"name": "名称",
3434
"name_placeholder": "知识库显示名称",
3535

36+
"language": "大模型语言",
37+
"language_zh_CN": "中文",
38+
"language_en_US": "英文",
39+
3640
"description": "描述",
3741
"description_placeholder": "请简要描述该知识库的整体内容",
3842

0 commit comments

Comments
 (0)