feat:增加根据当前路由路径快捷获取语言翻译的函数

This commit is contained in:
妙码生花 2023-02-27 09:41:11 +08:00
parent eb648f24d2
commit 3da9e62f68

View File

@ -9,6 +9,8 @@ import { useSiteConfig } from '../stores/siteConfig'
import { useTitle } from '@vueuse/core'
import { i18n } from '../lang'
import { getUrl } from './axios'
import { adminBaseRoute } from '/@/router/static'
import { trim, trimStart } from 'lodash-es'
export function registerIcons(app: App) {
/*
@ -212,6 +214,24 @@ export const fullUrl = (relativeUrl: string, domain = '') => {
return domain + relativeUrl
}
/**
*
* @param key key使
*/
export const __ = (key: string) => {
let path = router.currentRoute.value.path
if (path == '/') path = trimStart(window.location.hash, '#')
let langPath = ''
if (isAdminApp()) {
langPath = path.slice(path.indexOf(adminBaseRoute.path) + adminBaseRoute.path.length)
langPath = trim(langPath, '/').replaceAll('/', '.')
} else {
langPath = trim(path, '/').replaceAll('/', '.')
}
langPath = langPath ? langPath + '.' + key : key
return i18n.global.te(langPath) ? i18n.global.t(langPath) : i18n.global.t(key)
}
/**
*
*