Files
dajiankang-uniapp/uni_modules/wot-design-uni/components/composables/useTranslate.ts
PC-202306242200\Administrator 1c24452b6c first commit
2026-03-28 23:10:55 +08:00

13 lines
508 B
TypeScript

import { camelCase, getPropByPath, isDef, isFunction } from '../common/util'
import Locale from '../../locale'
export const useTranslate = (name?: string) => {
const prefix = name ? camelCase(name) + '.' : ''
const translate = (key: string, ...args: unknown[]) => {
const currentMessages = Locale.messages()
const message = getPropByPath(currentMessages, prefix + key)
return isFunction(message) ? message(...args) : isDef(message) ? message : `${prefix}${key}`
}
return { translate }
}