feat: i18n plugin

This commit is contained in:
xiaozzzi 2024-01-12 18:58:46 +08:00
parent df0c09e085
commit 393cc89374
8 changed files with 97 additions and 10 deletions

View File

@ -1,3 +1,12 @@
// 正常工作。
export {}
declare module '@renderer/assets/iconfont/iconfont.js'
declare module 'highlight.js'
declare module 'katex'
declare module 'katex'
declare module 'vue' {
interface ComponentCustomProperties {
$t: (key: string) => string
}
}

View File

@ -1,5 +1,14 @@
export const all = {
treedoc: {
loading: 'One moment please...'
import type { Temp } from './types'
export const en: Temp = {
editor: {
treeDoc: {
loading: 'loading....'
}
},
picture: {
treeDoc: {
loading: ''
}
}
}
}

View File

@ -0,0 +1,12 @@
import { App } from 'vue'
import { useI18n } from './useI18n'
const i18n = useI18n()
export default {
install: (app: App) => {
app.config.globalProperties.$t = (key: string) => {
return i18n.getValue(key)
}
}
}

View File

@ -0,0 +1,13 @@
const template = {
editor: {
treeDoc: {
loading: ''
}
},
picture: {
treeDoc: {
loading: ''
}
}
}
export type Temp = typeof template

View File

@ -0,0 +1,33 @@
import { ref } from 'vue'
import { zhCn } from './zh-cn'
import { en } from './en'
import { Temp } from './types'
const locale = ref('zhCn')
export const useI18n = () => {
const getValue = (key: string): string => {
let k: any = key.split('.').reduce((o, i) => {
if (o) {
return o[i]
}
}, getLocale())
return k as string
}
const getLocale = (): Temp => {
let l = locale.value
if (l === 'zh-cn') {
return zhCn
}
if (l === 'en') {
return en
}
return zhCn
}
return {
locale,
getValue,
getLocale
}
}

View File

@ -0,0 +1,14 @@
import type { Temp } from './types'
export const zhCn: Temp = {
editor: {
treeDoc: {
loading: '加载中'
}
},
picture: {
treeDoc: {
loading: ''
}
}
}

View File

@ -1,5 +0,0 @@
export const all = {
treedoc: {
loading: '正在读取文档...'
}
}

View File

@ -6,6 +6,7 @@ import '@renderer/assets/styles/index.scss'
import { createApp } from 'vue'
import App from './App.vue'
import i18n from './i18n/plugin'
import 'element-plus/es/components/message/style/css'
import 'element-plus/es/components/message-box/style/css'
@ -25,6 +26,7 @@ import BLRow from '@renderer/components/BLRow.vue'
import BLCol from '@renderer/components/BLCol.vue'
const app = createApp(App)
app.use(i18n)
app.use(pinia)
app.use(router)
app.component('bl-tag', BLTag).component('bl-row', BLRow).component('bl-col', BLCol)