mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-22 15:24:09 +00:00
feat:增加根据当前路由路径快捷获取语言翻译的函数
This commit is contained in:
parent
eb648f24d2
commit
3da9e62f68
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件类型效验,主要用于云存储
|
||||
* 服务端并不能单纯此函数来限制文件上传
|
||||
|
Loading…
Reference in New Issue
Block a user