refine: i18n

This commit is contained in:
菲鸽 2024-06-16 16:36:11 +08:00
parent 236d002c7c
commit 94e8962bbb
2 changed files with 5 additions and 6 deletions

View File

@ -59,13 +59,13 @@ function formatI18n(template: string, data?: any) {
/** /**
* t('introduction',{name:'张三',detail:{height:178,weight:'75kg'}}) * t('introduction',{name:'张三',detail:{height:178,weight:'75kg'}})
* t('introduction',{name:'张三',detail:{height:178,weight:'75kg'}}) * => formatI18n('我是{name},身高{detail.height},体重{detail.weight}',{name:'张三',detail:{height:178,weight:'75kg'}})
* * key的 data
* @param template eg: `我是{name}` * @param template eg: `我是{name}`
* @param {Object|undefined} obj key与多语言字符串对应eg: `{name:'菲鸽'}` * @param {Object|undefined} data key与多语言字符串对应eg: `{name:'菲鸽'}`
* @returns * @returns
*/ */
export function t(key, obj?) { export function t(key, data?) {
return formatI18n(getTemplateByKey(key), obj) return formatI18n(getTemplateByKey(key), data)
} }
export default i18n export default i18n

View File

@ -2,7 +2,6 @@ import { t } from '@/locale/index'
/** 非vue 文件使用 i18n */ /** 非vue 文件使用 i18n */
export const testI18n = () => { export const testI18n = () => {
console.log(t('app.name'))
// 下面同样生效 // 下面同样生效
uni.showModal({ uni.showModal({
title: 'i18n 测试', title: 'i18n 测试',