mirror of
https://github.com/blossom-editor/blossom
synced 2024-11-17 14:39:21 +08:00
feat: i18n plugin
This commit is contained in:
parent
df0c09e085
commit
393cc89374
11
blossom-editor/src/renderer/src/declaration.d.ts
vendored
11
blossom-editor/src/renderer/src/declaration.d.ts
vendored
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
blossom-editor/src/renderer/src/i18n/plugin.ts
Normal file
12
blossom-editor/src/renderer/src/i18n/plugin.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
13
blossom-editor/src/renderer/src/i18n/types.ts
Normal file
13
blossom-editor/src/renderer/src/i18n/types.ts
Normal file
@ -0,0 +1,13 @@
|
||||
const template = {
|
||||
editor: {
|
||||
treeDoc: {
|
||||
loading: ''
|
||||
}
|
||||
},
|
||||
picture: {
|
||||
treeDoc: {
|
||||
loading: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
export type Temp = typeof template
|
33
blossom-editor/src/renderer/src/i18n/useI18n.ts
Normal file
33
blossom-editor/src/renderer/src/i18n/useI18n.ts
Normal 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
|
||||
}
|
||||
}
|
14
blossom-editor/src/renderer/src/i18n/zh-cn.ts
Normal file
14
blossom-editor/src/renderer/src/i18n/zh-cn.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import type { Temp } from './types'
|
||||
|
||||
export const zhCn: Temp = {
|
||||
editor: {
|
||||
treeDoc: {
|
||||
loading: '加载中'
|
||||
}
|
||||
},
|
||||
picture: {
|
||||
treeDoc: {
|
||||
loading: ''
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
export const all = {
|
||||
treedoc: {
|
||||
loading: '正在读取文档...'
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user