forked from zguiy/utils
工具完成
This commit is contained in:
23
src/config/i18n/index.ts
Normal file
23
src/config/i18n/index.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import zh from './zh'
|
||||
import en from './en'
|
||||
import type { Language } from '@/types/tools'
|
||||
|
||||
export const locales = {
|
||||
zh,
|
||||
en
|
||||
}
|
||||
|
||||
export const getTranslation = (lang: Language = 'zh') => locales[lang]
|
||||
|
||||
export const t = (key: string, lang: Language = 'zh') => {
|
||||
const keys = key.split('.')
|
||||
let value: any = locales[lang]
|
||||
|
||||
for (const k of keys) {
|
||||
value = value?.[k]
|
||||
}
|
||||
|
||||
return value || key
|
||||
}
|
||||
|
||||
export default locales
|
||||
Reference in New Issue
Block a user