Skip to content

Commit 3f81097

Browse files
committed
Use i18n of element-plus
1 parent b4ea221 commit 3f81097

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

src/app/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import 'element-plus/lib/theme-chalk/index.css'
44
import './styles' // global css
55
import installRouter from './router'
66
import '../common/console-logger'
7+
import '../common/element-plus'
78

89
const app: App = createApp(Main)
9-
1010
installRouter(app)
1111
app.mount('#app')

src/app/layout/menu.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { computed, defineComponent, h, onMounted } from "@vue/runtime-core"
1+
import { defineComponent, h, onMounted } from "vue"
22
import { ElMenu, ElMenuItem, ElSubmenu } from "element-plus"
3-
import { Ref, ref } from "vue"
43
import { RouteLocationNormalizedLoaded, useRoute, useRouter } from "vue-router"
54
import { t } from "../../common/vue-i18n"
65

@@ -41,12 +40,12 @@ const ALL_MENU: MenuItem[] = [
4140

4241
const _default = defineComponent<{}, {}>(() => {
4342
const router = useRouter()
44-
const currentRoute = useRoute().path
43+
const currentRoute: RouteLocationNormalizedLoaded = useRoute()
4544

4645
onMounted(() => document.title = t('menu.data'))
4746

4847
const openMenu = (route: string, title: string) => {
49-
if (currentRoute !== route) {
48+
if (currentRoute.path !== route) {
5049
router.push(route)
5150
document.title = t(title)
5251
}
@@ -76,7 +75,7 @@ const _default = defineComponent<{}, {}>(() => {
7675

7776
const menuItems = () => ALL_MENU.map(renderMenu)
7877

79-
return () => h(ElMenu, { defaultActive: currentRoute }, { default: menuItems })
78+
return () => h(ElMenu, { defaultActive: currentRoute.path }, { default: menuItems })
8079
})
8180

8281
export default _default

src/common/element-plus.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Process locale
2+
import { locale, Locale } from '../common/vue-i18n'
3+
import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
4+
import enLang from 'element-plus/lib/locale/lang/en'
5+
import { locale as eleLocale } from 'element-plus'
6+
7+
if (locale === Locale.EN) {
8+
eleLocale(enLang)
9+
} else if (locale === Locale.ZH_CN) {
10+
eleLocale(zhLocale)
11+
}

src/common/vue-i18n.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { VNode } from 'vue'
22
import { vueMessages, defaultLocale } from '../locale'
33

4+
export enum Locale {
5+
ZH_CN = 'zh_CN',
6+
EN = 'en'
7+
}
48

59
// Standardize the locale code according to the Chrome locale code
6-
const chrome2I18n = {
7-
'zh-CN': 'zh_CN',
8-
'zh-TW': 'zh_TW',
9-
'en-US': 'en',
10-
'en-GB': 'en'
10+
const chrome2I18n: { [key: string]: Locale } = {
11+
'zh-CN': Locale.ZH_CN,
12+
'zh-TW': Locale.ZH_CN,
13+
'en-US': Locale.EN,
14+
'en-GB': Locale.EN
1115
}
1216

1317
/**
@@ -25,7 +29,9 @@ const chromeLocale2ExtensionLocale = (chromeLocale: string) => {
2529
return chrome2I18n[chromeLocale] || chromeLocale
2630
}
2731

28-
const message: any = vueMessages[chromeLocale2ExtensionLocale(chrome.i18n.getUILanguage())] || {}
32+
export const locale = chromeLocale2ExtensionLocale(chrome.i18n.getUILanguage())
33+
34+
const message: any = vueMessages[locale] || {}
2935

3036
export declare type I18nResultItem = VNode | string
3137

src/locale/components/item.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = {
77
time: '打开次数',
88
operation: {
99
label: '操作',
10-
minWidth: '220px',
1110
delete: '删除',
1211
add2Whitelist: '白名单',
1312
removeFromWhitelist: '启用',
@@ -27,7 +26,6 @@ module.exports = {
2726
time: 'Visit Count',
2827
operation: {
2928
label: 'Operations',
30-
minWidth: '240px',
3129
delete: 'Delete',
3230
add2Whitelist: 'Whitelist',
3331
removeFromWhitelist: 'Enable',
@@ -47,7 +45,6 @@ module.exports = {
4745
time: '訪問回数',
4846
operation: {
4947
label: '操作',
50-
minWidth: '240px',
5148
delete: '削除',
5249
add2Whitelist: 'ホワイトリスト',
5350
removeFromWhitelist: '有効にする',

src/popup/app.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const dataRef: Ref<SiteInfo[]> = ref([])
3434
const queryDataAndUpdate = () => {
3535
const param = { date: new Date(), mergeDomain: mergeDomainRef.value, sort: typeRef.value }
3636
timerDatabase.select(rows => {
37-
console.log(rows)
3837
const result = []
3938
const other: SiteInfo = { host: t('popup.otherLabel'), focus: 0, total: 0, date: '0000-00-00', time: 0 }
4039
for (let i = 0; i < rows.length; i++) {

0 commit comments

Comments
 (0)