refactor:优化据路由翻译函数

This commit is contained in:
妙码生花 2023-02-28 07:58:13 +08:00
parent 5b96bc062a
commit 970ccb6596

View File

@ -11,6 +11,7 @@ import { i18n } from '../lang'
import { getUrl } from './axios'
import { adminBaseRoute } from '/@/router/static'
import { trim, trimStart } from 'lodash-es'
import { TranslateOptions } from 'vue-i18n'
export function registerIcons(app: App) {
/*
@ -217,8 +218,11 @@ export const fullUrl = (relativeUrl: string, domain = '') => {
/**
*
* @param key key使
* @param named
* @param options
* @returns Translated message
*/
export const __ = (key: string) => {
export const __ = (key: string, named?: Record<string, unknown>, options?: TranslateOptions<string>) => {
let path = router.currentRoute.value.path
if (path == '/') path = trimStart(window.location.hash, '#')
let langPath = ''
@ -229,7 +233,7 @@ export const __ = (key: string) => {
langPath = trim(path, '/').replaceAll('/', '.')
}
langPath = langPath ? langPath + '.' + key : key
return i18n.global.te(langPath) ? i18n.global.t(langPath) : i18n.global.t(key)
return i18n.global.te(langPath) ? i18n.global.t(langPath, named ?? {}, options) : i18n.global.t(key, named ?? {}, options)
}
/**