Skip to content

Commit c4de677

Browse files
feat: i18n
1 parent 7ea0824 commit c4de677

File tree

17 files changed

+136
-92
lines changed

17 files changed

+136
-92
lines changed

ui/src/api/type/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface User {
2525
is_edit_password?: boolean
2626
IS_XPACK?: boolean
2727
XPACK_LICENSE_IS_VALID?: boolean
28+
language: string
2829
}
2930

3031
interface LoginRequest {

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ import { useRoute, useRouter } from 'vue-router'
184184
import { getImgUrl } from '@/utils/utils'
185185
import bus from '@/bus'
186186
import 'recorder-core/src/engine/mp3'
187-
188187
import 'recorder-core/src/engine/mp3-engine'
189188
import { MsgWarning } from '@/utils/message'
190189
import useStore from '@/stores'
190+
import { t } from '@/locales'
191191
const router = useRouter()
192192
const route = useRoute()
193193
const { application } = useStore()

ui/src/components/ai-chat/component/control/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import bus from '@/bus'
1616
import { ref, nextTick, onMounted } from 'vue'
1717
import { t } from '@/locales'
1818
const isOpen = ref<boolean>(false)
19-
const eventVal = ref({})
19+
const eventVal = ref()
2020
function getSelection() {
2121
const selection = window.getSelection()
2222
if (selection && selection.anchorNode == null) {

ui/src/components/app-table/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<script setup lang="ts">
4646
import { ref, nextTick, watch, computed, onMounted } from 'vue'
4747
import { MsgError } from '@/utils/message'
48+
import { t } from '@/locales'
4849
defineOptions({ name: 'AppTable' })
4950
5051
import useStore from '@/stores'
@@ -102,7 +103,7 @@ function submitHandle() {
102103
loading.value = false
103104
}, 200)
104105
} else {
105-
MsgError(`${props.quickCreateName}不能为空!`)
106+
MsgError(`${props.quickCreateName}${t('components.dynamicsForm.tip.requiredMessage')}`)
106107
}
107108
}
108109

ui/src/components/dynamics-form/constructor/items/MultiSelectConstructor.vue

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<el-form-item>
33
<template #label>
44
<div class="flex-between">
5-
选项值
5+
{{ $t('components.dynamicsForm.Select.label') }}
66
<el-button link type="primary" @click.stop="addOption()">
77
<el-icon class="mr-4">
88
<Plus />
@@ -12,13 +12,13 @@
1212
</div>
1313
</template>
1414
<el-row style="width: 100%" :gutter="10">
15-
<el-col :span="10"
16-
><div class="grid-content ep-bg-purple" />
17-
标签</el-col
18-
>
15+
<el-col :span="10">
16+
<div class="grid-content ep-bg-purple" />
17+
{{ $t('components.dynamicsForm.tag.label') }}
18+
</el-col>
1919
<el-col :span="12"
2020
><div class="grid-content ep-bg-purple" />
21-
选项值</el-col
21+
{{ $t('components.dynamicsForm.Select.label') }}</el-col
2222
>
2323
</el-row>
2424
<el-row
@@ -30,11 +30,13 @@
3030
>
3131
<el-col :span="10"
3232
><div class="grid-content ep-bg-purple" />
33-
<el-input v-model="formValue.option_list[$index].label" placeholder="请输入选项标签"
33+
<el-input v-model="formValue.option_list[$index].label" :placeholder="$t('components.dynamicsForm.tag.placeholder')"
3434
/></el-col>
3535
<el-col :span="12"
3636
><div class="grid-content ep-bg-purple" />
37-
<el-input v-model="formValue.option_list[$index].value" placeholder="请输入选项值"
37+
<el-input
38+
v-model="formValue.option_list[$index].value"
39+
:placeholder="$t('components.dynamicsForm.Select.label')"
3840
/></el-col>
3941
<el-col :span="1"
4042
><div class="grid-content ep-bg-purple" />
@@ -50,7 +52,11 @@
5052
:label="$t('components.dynamicsForm.default.label')"
5153
:required="formValue.required"
5254
prop="default_value"
53-
:rules="formValue.required ? [{ required: true, message: $t('components.dynamicsForm.default.requiredMessage') }] : []"
55+
:rules="
56+
formValue.required
57+
? [{ required: true, message: $t('components.dynamicsForm.default.requiredMessage') }]
58+
: []
59+
"
5460
>
5561
<div class="defaultValueCheckbox">
5662
<el-checkbox

ui/src/components/dynamics-form/constructor/items/RadioCardConstructor.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<el-form-item>
33
<template #label>
44
<div class="flex-between">
5-
选项值
5+
{{ $t('components.dynamicsForm.Select.label') }}
66
<el-button link type="primary" @click.stop="addOption()">
77
<el-icon class="mr-4">
88
<Plus />
@@ -13,13 +13,13 @@
1313
</template>
1414

1515
<el-row style="width: 100%" :gutter="10">
16-
<el-col :span="10"
17-
><div class="grid-content ep-bg-purple" />
18-
标签</el-col
19-
>
16+
<el-col :span="10">
17+
<div class="grid-content ep-bg-purple" />
18+
{{ $t('components.dynamicsForm.tag.label') }}
19+
</el-col>
2020
<el-col :span="12"
2121
><div class="grid-content ep-bg-purple" />
22-
选项值</el-col
22+
{{ $t('components.dynamicsForm.Select.label') }}</el-col
2323
>
2424
</el-row>
2525
<el-row
@@ -31,11 +31,13 @@
3131
>
3232
<el-col :span="10"
3333
><div class="grid-content ep-bg-purple" />
34-
<el-input v-model="formValue.option_list[$index].label" placeholder="请输入选项标签"
34+
<el-input v-model="formValue.option_list[$index].label" :placeholder="$t('components.dynamicsForm.tag.placeholder')"
3535
/></el-col>
3636
<el-col :span="12"
3737
><div class="grid-content ep-bg-purple" />
38-
<el-input v-model="formValue.option_list[$index].value" placeholder="请输入选项值"
38+
<el-input
39+
v-model="formValue.option_list[$index].value"
40+
:placeholder="$t('components.dynamicsForm.Select.label')"
3941
/></el-col>
4042
<el-col :span="1"
4143
><div class="grid-content ep-bg-purple" />

ui/src/components/dynamics-form/constructor/items/RadioRowConstructor.vue

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<el-form-item>
33
<template #label>
44
<div class="flex-between">
5-
选项值
5+
{{ $t('components.dynamicsForm.Select.label') }}
66
<el-button link type="primary" @click.stop="addOption()">
77
<el-icon class="mr-4">
88
<Plus />
@@ -13,14 +13,14 @@
1313
</template>
1414

1515
<el-row style="width: 100%" :gutter="10">
16-
<el-col :span="10"
17-
><div class="grid-content ep-bg-purple" />
18-
标签</el-col
19-
>
20-
<el-col :span="12"
21-
><div class="grid-content ep-bg-purple" />
22-
选项值</el-col
23-
>
16+
<el-col :span="10">
17+
<div class="grid-content ep-bg-purple" />
18+
{{ $t('components.dynamicsForm.tag.label') }}
19+
</el-col>
20+
<el-col :span="12">
21+
<div class="grid-content ep-bg-purple" />
22+
{{ $t('components.dynamicsForm.Select.label') }}
23+
</el-col>
2424
</el-row>
2525
<el-row
2626
style="width: 100%"
@@ -31,11 +31,15 @@
3131
>
3232
<el-col :span="10"
3333
><div class="grid-content ep-bg-purple" />
34-
<el-input v-model="formValue.option_list[$index].label" placeholder="请输入选项标签"
34+
<el-input
35+
v-model="formValue.option_list[$index].label"
36+
:placeholder="$t('components.dynamicsForm.tag.placeholder')"
3537
/></el-col>
3638
<el-col :span="12"
3739
><div class="grid-content ep-bg-purple" />
38-
<el-input v-model="formValue.option_list[$index].value" placeholder="请输入选项值"
40+
<el-input
41+
v-model="formValue.option_list[$index].value"
42+
:placeholder="$t('components.dynamicsForm.Select.label')"
3943
/></el-col>
4044
<el-col :span="1"
4145
><div class="grid-content ep-bg-purple" />

ui/src/components/dynamics-form/constructor/items/SingleSelectConstructor.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<el-form-item>
33
<template #label>
44
<div class="flex-between">
5-
选项值
5+
{{ $t('components.dynamicsForm.Select.label') }}
66
<el-button link type="primary" @click.stop="addOption()">
77
<el-icon class="mr-4">
88
<Plus />
@@ -15,12 +15,12 @@
1515
<el-row style="width: 100%" :gutter="10">
1616
<el-col :span="10"
1717
><div class="grid-content ep-bg-purple" />
18-
标签</el-col
19-
>
20-
<el-col :span="12"
21-
><div class="grid-content ep-bg-purple" />
22-
选项值</el-col
18+
{{ $t('components.dynamicsForm.tag.label') }}</el-col
2319
>
20+
<el-col :span="12">
21+
<div class="grid-content ep-bg-purple" />
22+
{{ $t('components.dynamicsForm.Select.label') }}
23+
</el-col>
2424
</el-row>
2525
<el-row
2626
style="width: 100%"
@@ -31,11 +31,13 @@
3131
>
3232
<el-col :span="10"
3333
><div class="grid-content ep-bg-purple" />
34-
<el-input v-model="formValue.option_list[$index].label" placeholder="请输入选项标签"
34+
<el-input v-model="formValue.option_list[$index].label" :placeholder="$t('components.dynamicsForm.tag.placeholder')"
3535
/></el-col>
3636
<el-col :span="12"
3737
><div class="grid-content ep-bg-purple" />
38-
<el-input v-model="formValue.option_list[$index].value" placeholder="请输入选项值"
38+
<el-input
39+
v-model="formValue.option_list[$index].value"
40+
:placeholder="$t('components.dynamicsForm.Select.label')"
3941
/></el-col>
4042
<el-col :span="1"
4143
><div class="grid-content ep-bg-purple" />

ui/src/components/dynamics-form/constructor/items/SliderConstructor.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
</template>
7474
<script setup lang="ts">
7575
import { computed, onBeforeMount, watch } from 'vue'
76-
76+
import { t } from '@/locales'
7777
const props = defineProps<{
7878
modelValue: any
7979
}>()
@@ -101,7 +101,7 @@ const getData = () => {
101101
props_info: {
102102
rules: [
103103
{
104-
message: formValue.value.label + '不能为空',
104+
message: formValue.value.label + t('components.dynamicsForm.tip.requiredMessage'),
105105
trigger: 'blur',
106106
required: formValue.value.required
107107
}

ui/src/locales/index.ts

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,71 @@
1-
import { useLocalStorage, usePreferredLanguages } from '@vueuse/core';
2-
import { computed } from 'vue';
3-
import { createI18n } from 'vue-i18n';
1+
import { useLocalStorage, usePreferredLanguages } from '@vueuse/core'
2+
import { computed } from 'vue'
43

4+
import { createI18n } from 'vue-i18n'
5+
import useStore from '@/stores'
6+
const { user } = useStore()
57
// 导入语言文件
6-
const langModules = import.meta.glob('./lang/*/index.ts', { eager: true }) as Record<string, () => Promise<{ default: Object }>>;
8+
const langModules = import.meta.glob('./lang/*/index.ts', { eager: true }) as Record<
9+
string,
10+
() => Promise<{ default: Object }>
11+
>
712

8-
const langModuleMap = new Map<string, Object>();
13+
const langModuleMap = new Map<string, Object>()
914

10-
export const langCode: Array<string> = [];
15+
export const langCode: Array<string> = []
1116

12-
export const localeConfigKey = 'MaxKB-locale';
17+
export const localeConfigKey = 'MaxKB-locale'
1318

1419
// 获取浏览器默认语言环境
15-
const languages = usePreferredLanguages();
20+
const languages = usePreferredLanguages()
1621

1722
// 生成语言模块列表
1823
const generateLangModuleMap = () => {
19-
const fullPaths = Object.keys(langModules);
20-
fullPaths.forEach((fullPath) => {
21-
const k = fullPath.replace('./lang', '');
22-
const startIndex = 1;
23-
const lastIndex = k.lastIndexOf('/');
24-
const code = k.substring(startIndex, lastIndex);
25-
langCode.push(code);
26-
langModuleMap.set(code, langModules[fullPath]);
27-
});
28-
};
24+
const fullPaths = Object.keys(langModules)
25+
fullPaths.forEach((fullPath) => {
26+
const k = fullPath.replace('./lang', '')
27+
const startIndex = 1
28+
const lastIndex = k.lastIndexOf('/')
29+
const code = k.substring(startIndex, lastIndex)
30+
langCode.push(code)
31+
langModuleMap.set(code, langModules[fullPath])
32+
})
33+
}
2934

3035
// 导出 Message
3136
const importMessages = computed(() => {
32-
generateLangModuleMap();
37+
generateLangModuleMap()
3338

34-
const message: Recordable = {};
35-
langModuleMap.forEach((value: any, key) => {
36-
message[key] = value.default;
37-
});
38-
return message;
39-
});
39+
const message: Recordable = {}
40+
langModuleMap.forEach((value: any, key) => {
41+
message[key] = value.default
42+
})
43+
return message
44+
})
4045

4146
export const i18n = createI18n({
42-
legacy: false,
43-
locale: useLocalStorage(localeConfigKey, 'zh_CN').value || languages.value[0] || 'zh_CN',
44-
fallbackLocale: 'zh_CN',
45-
messages: importMessages.value,
46-
globalInjection: true,
47-
});
47+
legacy: false,
48+
locale: user.getLanguage() || languages.value[0] || 'zh_CN',
49+
fallbackLocale: 'zh_CN',
50+
messages: importMessages.value,
51+
globalInjection: true
52+
})
4853

4954
export const langList = computed(() => {
50-
if (langModuleMap.size === 0) generateLangModuleMap();
55+
if (langModuleMap.size === 0) generateLangModuleMap()
5156

52-
const list:any=[]
53-
langModuleMap.forEach((value: any, key) => {
54-
list.push({
55-
label: value.default.lang,
56-
value: key,
57-
});
58-
});
57+
const list: any = []
58+
langModuleMap.forEach((value: any, key) => {
59+
list.push({
60+
label: value.default.lang,
61+
value: key
62+
})
63+
})
5964

60-
return list;
61-
});
65+
return list
66+
})
6267

6368
// @ts-ignore
64-
export const { t } = i18n.global;
69+
export const { t } = i18n.global
6570

66-
export default i18n;
71+
export default i18n

0 commit comments

Comments
 (0)