Skip to content

Commit 576391b

Browse files
feat: i18n
1 parent 09f2966 commit 576391b

File tree

9 files changed

+112
-7
lines changed

9 files changed

+112
-7
lines changed

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
"@npkg/tinymce-plugins": "^0.0.7",
1414
"@tinymce/tinymce-vue": "^5.1.0",
1515
"dayjs": "^1.11.13",
16-
"element-plus": "^2.9.11",
16+
"element-plus": "^2.10.1",
1717
"lodash": "^4.17.21",
1818
"snowflake-id": "^1.1.0",
1919
"tinymce": "^5.8.2",
2020
"vue": "^3.5.13",
21+
"vue-i18n": "^9.14.4",
2122
"vue-router": "^4.5.0",
2223
"web-storage-cache": "^1.1.1"
2324
},

frontend/src/App.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
<script setup lang="ts">
2+
import { computed } from 'vue'
3+
import { ElConfigProvider } from 'element-plus'
4+
import { getElementLocale } from '@/i18n'
5+
const elLanguage = computed(() => {
6+
return getElementLocale()
7+
})
28
</script>
39

410
<template>
5-
<router-view />
11+
<el-config-provider :locale="elLanguage">
12+
<router-view />
13+
</el-config-provider>
614
</template>
715

816
<style scoped>

frontend/src/components/layout/index.vue

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343

4444
<div v-else class="top-bar-title">
4545
<span class="split"/>
46-
<span>System manage</span>
46+
<!-- <span>System manage</span> -->
47+
<span>{{ t('common.system_manage') }}</span>
4748
</div>
4849

4950

@@ -76,6 +77,21 @@
7677
<el-dropdown-menu>
7778
<el-dropdown-item @click="switchLayout">Switch Layout</el-dropdown-item>
7879
<el-dropdown-item @click="logout">Logout</el-dropdown-item>
80+
81+
<el-dropdown @command="changeLanguage">
82+
<div class="lang-switch">
83+
Language
84+
<el-icon>
85+
<i class="el-icon-arrow-down"/>
86+
</el-icon>
87+
</div>
88+
<template #dropdown>
89+
<el-dropdown-menu>
90+
<el-dropdown-item command="en">English</el-dropdown-item>
91+
<el-dropdown-item command="zh-CN">中文</el-dropdown-item>
92+
</el-dropdown-menu>
93+
</template>
94+
</el-dropdown>
7995
</el-dropdown-menu>
8096
</template>
8197
</el-dropdown>
@@ -153,7 +169,9 @@ import icon_user from '@/assets/svg/icon_user.svg'
153169
import icon_ai from '@/assets/svg/icon_ai.svg'
154170
import {ArrowLeftBold} from '@element-plus/icons-vue'
155171
import {useCache} from '@/utils/useCache'
172+
import { useI18n } from 'vue-i18n'
156173
174+
const { locale, t } = useI18n()
157175
const {wsCache} = useCache()
158176
const topLayout = ref(false)
159177
const router = useRouter()
@@ -215,6 +233,10 @@ const switchLayout = () => {
215233
topLayout.value = !topLayout.value
216234
wsCache.set('sqlbot-topbar-layout', topLayout.value)
217235
}
236+
237+
const changeLanguage = (lang: string) => {
238+
locale.value = lang
239+
}
218240
onMounted(() => {
219241
topLayout.value = wsCache.get('sqlbot-topbar-layout') || true
220242
})
@@ -536,4 +558,12 @@ onMounted(() => {
536558
}
537559
}
538560
}
561+
.lang-switch {
562+
cursor: pointer;
563+
padding: 0 12px;
564+
565+
&:hover {
566+
color: var(--el-color-primary);
567+
}
568+
}
539569
</style>

frontend/src/i18n/en.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"menu": {
3+
"dashboard": "Dashboard",
4+
"chat": "Chat",
5+
"datasource": "Data Source",
6+
"system": "System"
7+
},
8+
"common": {
9+
"back": "Back",
10+
"confirm": "Confirm",
11+
"cancel": "Cancel",
12+
"system_manage": "System Management"
13+
}
14+
}

frontend/src/i18n/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { createI18n } from 'vue-i18n'
2+
import en from './en.json'
3+
import zhCN from './zh-CN.json'
4+
import elementEnLocale from 'element-plus/es/locale/lang/en'
5+
import elementZhLocale from 'element-plus/es/locale/lang/zh-cn'
6+
7+
const getDefaultLocale = () => {
8+
/* const savedLang = localStorage.getItem('lang')
9+
return savedLang || 'zh-CN' */
10+
return 'zh-CN'
11+
}
12+
13+
const messages = {
14+
en: {
15+
...en,
16+
el: elementEnLocale
17+
},
18+
'zh-CN': {
19+
...zhCN,
20+
el: elementZhLocale
21+
}
22+
}
23+
24+
export const i18n = createI18n({
25+
legacy: false,
26+
locale: getDefaultLocale(),
27+
fallbackLocale: 'en',
28+
globalInjection: true,
29+
messages
30+
})
31+
32+
export const getElementLocale = () => {
33+
return i18n.global.locale.value === 'en' ? elementEnLocale : elementZhLocale
34+
}

frontend/src/i18n/zh-CN.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"menu": {
3+
"dashboard": "仪表盘",
4+
"chat": "聊天",
5+
"datasource": "数据源",
6+
"system": "系统"
7+
},
8+
"common": {
9+
"back": "返回",
10+
"confirm": "确认",
11+
"cancel": "取消",
12+
"system_manage": "系统管理"
13+
}
14+
}

frontend/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { createPinia } from 'pinia'
33
import './style.less'
44
import App from './App.vue'
55
import router from './router'
6+
import { i18n } from './i18n'
67
// import 'element-plus/dist/index.css'
78
const app = createApp(App)
89
const pinia = createPinia()
910

1011
app.use(pinia)
1112
app.use(router)
13+
app.use(i18n)
1214
app.mount('#app')

frontend/src/router/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import chat from "@/views/chat/index.vue";
77
import ds from "@/views/ds/index.vue";
88
import DashboardEditor from "@/views/dashboard/editor/index.vue";
99
import Dashboard from "@/views/dashboard/index.vue";
10-
// import setting from "@/views/setting/index.vue";
10+
import Model from "@/views/system/model/index.vue";
11+
import User from "@/views/system/user/index.vue";
1112
import { watchRouter } from "./watch";
1213
const router = createRouter({
1314
history: createWebHashHistory(),
@@ -95,17 +96,17 @@ const router = createRouter({
9596
{
9697
path: "user",
9798
name: "user",
98-
component: () => import("@/views/system/user/index.vue"),
99+
component: User,
99100
meta: { title: "User Management", icon: "icon_user" },
100101
},
101102
{
102103
path: "model",
103104
name: "model",
104-
component: () => import("@/views/system/model/index.vue"),
105+
component: Model,
105106
meta: { title: "AI Model Configuration", icon: "icon_ai" },
106107
},
107108
],
108-
},
109+
}
109110
],
110111
});
111112
watchRouter(router);

frontend/src/views/system/model/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
v-model:page-size="state.pageInfo.pageSize"
8181
:page-sizes="[10, 20, 30]"
8282
:background="true"
83+
:pager-count="5"
8384
layout="total, sizes, prev, pager, next, jumper"
8485
:total="state.pageInfo.total"
8586
@size-change="handleSizeChange"

0 commit comments

Comments
 (0)