From 29ddee8d06ed02365332f9b5b67e8736157f240f Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 20 Jan 2025 19:00:58 +0800 Subject: [PATCH] feat: i18n --- .../serializers/application_serializers.py | 3 +- .../locales/lang/en_US/components/ai-chat.ts | 32 ++++++++ .../lang/en_US/components/dynamics-form.ts | 78 +++++++++++++++++++ ui/src/locales/lang/en_US/components/index.ts | 9 ++- .../lang/en_US/views/application-overview.ts | 1 + .../locales/lang/zh_CN/components/ai-chat.ts | 2 +- .../lang/zh_CN/views/application-overview.ts | 1 + .../locales/lang/zh_TW/components/ai-chat.ts | 31 ++++++++ .../lang/zh_TW/components/dynamics-form.ts | 78 +++++++++++++++++++ ui/src/locales/lang/zh_TW/components/index.ts | 8 +- .../lang/zh_TW/views/application-overview.ts | 3 +- .../component/DisplaySettingDialog.vue | 23 +++++- .../component/XPackDisplaySettingDialog.vue | 18 ++++- ui/src/views/chat/pc/index.vue | 10 ++- 14 files changed, 283 insertions(+), 14 deletions(-) create mode 100644 ui/src/locales/lang/en_US/components/ai-chat.ts create mode 100644 ui/src/locales/lang/en_US/components/dynamics-form.ts create mode 100644 ui/src/locales/lang/zh_TW/components/ai-chat.ts create mode 100644 ui/src/locales/lang/zh_TW/components/dynamics-form.ts diff --git a/apps/application/serializers/application_serializers.py b/apps/application/serializers/application_serializers.py index b4dcd8c0d..e5316040f 100644 --- a/apps/application/serializers/application_serializers.py +++ b/apps/application/serializers/application_serializers.py @@ -399,7 +399,8 @@ class ApplicationSerializer(serializers.Serializer): 'access_num': application_access_token.access_num, 'white_active': application_access_token.white_active, 'white_list': application_access_token.white_list, - 'show_source': application_access_token.show_source + 'show_source': application_access_token.show_source, + 'language': application_access_token.language } class Authentication(serializers.Serializer): diff --git a/ui/src/locales/lang/en_US/components/ai-chat.ts b/ui/src/locales/lang/en_US/components/ai-chat.ts new file mode 100644 index 000000000..3a5ef132e --- /dev/null +++ b/ui/src/locales/lang/en_US/components/ai-chat.ts @@ -0,0 +1,32 @@ +export default { + noHistory: 'No History', + createChat: 'Create New Chat', + history: 'History', + only20history: 'Only showing the last 20 conversations', + question_count: 'Questions', + exportRecords: 'Export Chat Records', + chatId: 'Chat ID', + userInput: 'User Input', + passwordValidator: { + title: 'Enter password to open the link', + errorMessage1: 'Password cannot be empty', + errorMessage2: 'Incorrect password' + }, + tip: { + error500Message: 'Sorry, the service is currently under maintenance. Please try again later!', + errorIdentifyMessage: 'Unable to identify user', + errorLimitMessage: + 'Sorry, you have reached the maximum number of questions. Please try again tomorrow!' + }, + executionDetails: { + title: 'Execution Details', + paramInput: 'Parameter Input', + paramOutput: 'Parameter Output' + }, + KnowledgeSource: { + title: 'Knowledge Source', + referenceParagraph: 'Referenced Paragraph', + consume: 'Consumption', + consumeTime: 'Time Consumed' + } +} diff --git a/ui/src/locales/lang/en_US/components/dynamics-form.ts b/ui/src/locales/lang/en_US/components/dynamics-form.ts new file mode 100644 index 000000000..266ab6456 --- /dev/null +++ b/ui/src/locales/lang/en_US/components/dynamics-form.ts @@ -0,0 +1,78 @@ +export default { + input_type_list: { + TextInput: 'Text Input', + Slider: 'Slider', + SwitchInput: 'Switch', + SingleSelect: 'Single Select', + MultiSelect: 'Multi Select', + DatePicker: 'Date Picker', + JsonInput: 'JSON Text Input', + RadioCard: 'Radio Card', + RadioRow: 'Radio Row' + }, + default: { + label: 'Default Value', + placeholder: 'Please enter a default value', + requiredMessage: 'Default Value is a required property', + show: 'Show Default Value' + }, + tip: { + requiredMessage: 'Cannot be empty', + jsonMessage: 'Incorrect JSON format' + }, + searchBar: { + placeholder: 'Please enter keywords to search' + }, + paramForm: { + field: { + label: 'Parameter', + placeholder: 'Please enter a parameter', + requiredMessage: 'Parameter is a required property', + requiredMessage2: 'Only letters, numbers, and underscores are allowed' + }, + name: { + label: 'Display Name', + placeholder: 'Please enter a display name', + requiredMessage: 'Display Name is a required property' + }, + tooltip: { + label: 'Parameter Tooltip', + placeholder: 'Please enter a parameter tooltip' + }, + required: { + label: 'Is Required', + requiredMessage: 'Is Required is a required property' + }, + input_type: { + label: 'Component Type', + placeholder: 'Please select a component type', + requiredMessage: 'Component Type is a required property' + } + }, + DatePicker: { + placeholder: 'Select Date', + year: 'Year', + month: 'Month', + date: 'Date', + datetime: 'Date Time', + dataType: { + label: 'Date Type', + placeholder: 'Please select a date type' + }, + format: { + label: 'Format', + placeholder: 'Please select a format' + } + }, + Select: { + label: 'Option Value', + placeholder: 'Please enter an option value' + }, + tag: { + label: 'Tag', + placeholder: 'Please enter an option label' + }, + Slider: { + showInput: '' + } +} diff --git a/ui/src/locales/lang/en_US/components/index.ts b/ui/src/locales/lang/en_US/components/index.ts index bd77588db..4d9320646 100644 --- a/ui/src/locales/lang/en_US/components/index.ts +++ b/ui/src/locales/lang/en_US/components/index.ts @@ -1,4 +1,7 @@ - +import dynamicsForm from './dynamics-form' +import chat from './ai-chat' export default { - -}; + dynamicsForm, + chat, + noData: 'No Data' +} diff --git a/ui/src/locales/lang/en_US/views/application-overview.ts b/ui/src/locales/lang/en_US/views/application-overview.ts index 361dc1b7d..dfe174879 100644 --- a/ui/src/locales/lang/en_US/views/application-overview.ts +++ b/ui/src/locales/lang/en_US/views/application-overview.ts @@ -62,6 +62,7 @@ export default { }, SettingDisplayDialog: { dialogTitle: 'Display Settings', + languageLabel: 'Language', showSourceLabel: 'Show Source', showExecutionDetail: 'Show Execution Detail', restoreDefault: 'Restore Default', diff --git a/ui/src/locales/lang/zh_CN/components/ai-chat.ts b/ui/src/locales/lang/zh_CN/components/ai-chat.ts index cb9ab15b2..53022a4a0 100644 --- a/ui/src/locales/lang/zh_CN/components/ai-chat.ts +++ b/ui/src/locales/lang/zh_CN/components/ai-chat.ts @@ -4,7 +4,7 @@ export default { history: '历史记录', only20history: '仅显示最近 20 条对话', question_count: '条提问', - exportReords: '导出聊天记录', + exportRecords: '导出聊天记录', chatId: '对话id', userInput: '用户输入', passwordValidator: { diff --git a/ui/src/locales/lang/zh_CN/views/application-overview.ts b/ui/src/locales/lang/zh_CN/views/application-overview.ts index 6152e3015..c7dea2f2c 100644 --- a/ui/src/locales/lang/zh_CN/views/application-overview.ts +++ b/ui/src/locales/lang/zh_CN/views/application-overview.ts @@ -62,6 +62,7 @@ export default { }, SettingDisplayDialog: { dialogTitle: '显示设置', + languageLabel: '语言', showSourceLabel: '显示知识来源', showExecutionDetail: '显示执行详情', restoreDefault: '恢复默认', diff --git a/ui/src/locales/lang/zh_TW/components/ai-chat.ts b/ui/src/locales/lang/zh_TW/components/ai-chat.ts new file mode 100644 index 000000000..07eb962e3 --- /dev/null +++ b/ui/src/locales/lang/zh_TW/components/ai-chat.ts @@ -0,0 +1,31 @@ +export default { + noHistory: '暫無歷史記錄', + createChat: '新建對話', + history: '歷史記錄', + only20history: '僅顯示最近 20 條對話', + question_count: '條提問', + exportRecords: '導出聊天記錄', + chatId: '對話ID', + userInput: '用戶輸入', + passwordValidator: { + title: '請輸入密碼打開連結', + errorMessage1: '密碼不能為空', + errorMessage2: '密碼錯誤' + }, + tip: { + error500Message: '抱歉,當前正在維護,無法提供服務,請稍後再試!', + errorIdentifyMessage: '無法識別用戶身份', + errorLimitMessage: '抱歉,您的提問已達最大限制,請明天再來吧!' + }, + executionDetails: { + title: '執行詳細', + paramInput: '參數輸入', + paramOutput: '參數輸出' + }, + KnowledgeSource: { + title: '知識來源', + referenceParagraph: '引用分段', + consume: '消耗', + consumeTime: '耗時' + } +} diff --git a/ui/src/locales/lang/zh_TW/components/dynamics-form.ts b/ui/src/locales/lang/zh_TW/components/dynamics-form.ts new file mode 100644 index 000000000..1b1bd3ba5 --- /dev/null +++ b/ui/src/locales/lang/zh_TW/components/dynamics-form.ts @@ -0,0 +1,78 @@ +export default { + input_type_list: { + TextInput: '文字框', + Slider: '滑桿', + SwitchInput: '開關', + SingleSelect: '單選框', + MultiSelect: '多選框', + DatePicker: '日期選擇器', + JsonInput: 'JSON文字框', + RadioCard: '選項卡', + RadioRow: '單行選項卡' + }, + default: { + label: '預設值', + placeholder: '請輸入預設值', + requiredMessage: '預設值 為必填屬性', + show: '顯示預設值' + }, + tip: { + requiredMessage: '不能為空', + jsonMessage: 'JSON格式不正確' + }, + searchBar: { + placeholder: '請輸入關鍵字搜索' + }, + paramForm: { + field: { + label: '參數', + placeholder: '請輸入參數', + requiredMessage: '參數 為必填屬性', + requiredMessage2: '只能輸入字母、數字和底線' + }, + name: { + label: '顯示名稱', + placeholder: '請輸入顯示名稱', + requiredMessage: '顯示名稱 為必填屬性' + }, + tooltip: { + label: '參數提示說明', + placeholder: '請輸入參數提示說明' + }, + required: { + label: '是否必填', + requiredMessage: '是否必填 為必填屬性' + }, + input_type: { + label: '組件類型', + placeholder: '請選擇組件類型', + requiredMessage: '組件類型 為必填屬性' + } + }, + DatePicker: { + placeholder: '選擇日期', + year: '年', + month: '月', + date: '日期', + datetime: '日期時間', + dataType: { + label: '時間類型', + placeholder: '請選擇時間類型' + }, + format: { + label: '格式', + placeholder: '請選擇格式' + } + }, + Select: { + label: '選項值', + placeholder: '請輸入選項值' + }, + tag: { + label: '標籤', + placeholder: '請輸入選項標籤' + }, + Slider: { + showInput: '' + } +} diff --git a/ui/src/locales/lang/zh_TW/components/index.ts b/ui/src/locales/lang/zh_TW/components/index.ts index b1c6ea436..bafbb8f4a 100644 --- a/ui/src/locales/lang/zh_TW/components/index.ts +++ b/ui/src/locales/lang/zh_TW/components/index.ts @@ -1 +1,7 @@ -export default {} +import dynamicsForm from './dynamics-form' +import chat from './ai-chat' +export default { + dynamicsForm, + chat, + noData: '無匹配資料' +} diff --git a/ui/src/locales/lang/zh_TW/views/application-overview.ts b/ui/src/locales/lang/zh_TW/views/application-overview.ts index bd7b4969e..de374167a 100644 --- a/ui/src/locales/lang/zh_TW/views/application-overview.ts +++ b/ui/src/locales/lang/zh_TW/views/application-overview.ts @@ -57,10 +57,11 @@ export default { dialogTitle: '設定', allowCrossDomainLabel: '允許跨域位址', crossDomainPlaceholder: - '請輸入允許的跨域位址,開啟後不輸入跨域位址則不限制。\n跨域位址一行一個,如:\nhttp://127.0.0.1:5678 \nhttps://dataease.io', + '請輸入允許的跨域位址,開啟後不輸入跨域位址則不限制。\n跨域位址一行一個,如:\nhttp://127.0.0.1:5678 \nhttps://dataease.io' }, SettingDisplayDialog: { dialogTitle: '顯示設定', + languageLabel: '語言', showSourceLabel: '顯示知識來源', showExecutionDetail: '顯示執行細節', restoreDefault: '恢復預設', diff --git a/ui/src/views/application-overview/component/DisplaySettingDialog.vue b/ui/src/views/application-overview/component/DisplaySettingDialog.vue index 0098856d5..b7f83e40a 100644 --- a/ui/src/views/application-overview/component/DisplaySettingDialog.vue +++ b/ui/src/views/application-overview/component/DisplaySettingDialog.vue @@ -6,6 +6,19 @@ :close-on-press-escape="false" > + + {{ + $t('views.applicationOverview.appInfo.SettingDisplayDialog.languageLabel') + }} + + + + { } } }) - const open = (data: any, content: any) => { detail.value = content form.value.show_source = data.show_source + form.value.language = data.language + if (!form.value.language) { + form.value.language = 'zh-CN' + } dialogVisible.value = true } @@ -75,7 +91,8 @@ const submit = async (formEl: FormInstance | undefined) => { await formEl.validate((valid, fields) => { if (valid) { const obj = { - show_source: form.value.show_source + show_source: form.value.show_source, + language: form.value.language } applicationApi.putAccessToken(id as string, obj, loading).then((res) => { emit('refresh') diff --git a/ui/src/views/application-overview/component/XPackDisplaySettingDialog.vue b/ui/src/views/application-overview/component/XPackDisplaySettingDialog.vue index d5e3a9186..53c438573 100644 --- a/ui/src/views/application-overview/component/XPackDisplaySettingDialog.vue +++ b/ui/src/views/application-overview/component/XPackDisplaySettingDialog.vue @@ -79,6 +79,19 @@ +
+ {{ + $t('views.applicationOverview.appInfo.SettingDisplayDialog.languageLabel') + }} + + + +
@@ -378,7 +391,7 @@ import type { FormInstance, FormRules, UploadFiles } from 'element-plus' import { isAppIcon, isWorkFlow } from '@/utils/application' import applicationXpackApi from '@/api/application-xpack' import { MsgSuccess, MsgError } from '@/utils/message' -import { t } from '@/locales' +import { langList, t } from '@/locales' import useStore from '@/stores' import { cloneDeep } from 'lodash' @@ -393,6 +406,7 @@ const emit = defineEmits(['refresh']) const defaultSetting = { show_source: false, + language: 'zh-CN', show_history: true, draggable: true, show_guide: true, @@ -421,6 +435,7 @@ const form = ref({ const xpackForm = ref({ show_source: false, + language: 'zh-CN', show_history: false, draggable: false, show_guide: false, @@ -488,6 +503,7 @@ const open = (data: any, content: any) => { detail.value = content xpackForm.value.show_source = data.show_source xpackForm.value.show_history = data.show_history + xpackForm.value.language = data.language xpackForm.value.draggable = data.draggable xpackForm.value.show_guide = data.show_guide imgUrl.value.avatar = data.avatar diff --git a/ui/src/views/chat/pc/index.vue b/ui/src/views/chat/pc/index.vue index d4b288cb2..7a534bfee 100644 --- a/ui/src/views/chat/pc/index.vue +++ b/ui/src/views/chat/pc/index.vue @@ -107,12 +107,16 @@