修改国际版本
This commit is contained in:
@@ -1,5 +1,59 @@
|
||||
// i18n工具函数 - 用于在 Vue 3 setup 中安全获取 $t
|
||||
import { getCurrentInstance } from 'vue'
|
||||
import zhCN from '../locale/zh-CN.js'
|
||||
import enUS from '../locale/en-US.js'
|
||||
import idID from '../locale/id-ID.js'
|
||||
|
||||
const MESSAGE_MAP = {
|
||||
'zh-CN': zhCN,
|
||||
'en-US': enUS,
|
||||
'id-ID': idID
|
||||
}
|
||||
const LANGUAGE_STORAGE_KEY = 'language'
|
||||
|
||||
export function getAppLocale() {
|
||||
try {
|
||||
const lang = uni.getStorageSync(LANGUAGE_STORAGE_KEY)
|
||||
if (lang && MESSAGE_MAP[lang]) return lang
|
||||
} catch (_) {}
|
||||
return 'zh-CN'
|
||||
}
|
||||
|
||||
function lookupMessage(locale, key) {
|
||||
const segments = String(key).split('.')
|
||||
let node = MESSAGE_MAP[locale]
|
||||
for (const seg of segments) {
|
||||
if (node == null || typeof node !== 'object') return null
|
||||
node = node[seg]
|
||||
}
|
||||
return typeof node === 'string' ? node : null
|
||||
}
|
||||
|
||||
/** 非 Vue 组件场景下的文案翻译 */
|
||||
export function translate(key, values) {
|
||||
const locale = getAppLocale()
|
||||
let text = lookupMessage(locale, key) ?? lookupMessage('zh-CN', key) ?? key
|
||||
if (values && typeof values === 'object') {
|
||||
Object.entries(values).forEach(([k, v]) => {
|
||||
text = text.split(`{${k}}`).join(String(v))
|
||||
})
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
/** uni.showModal 封装:默认使用多语言取消/确认按钮 */
|
||||
export function showModalI18n(options = {}) {
|
||||
const { cancelText, confirmText, showCancel = true, ...rest } = options
|
||||
const modalOptions = {
|
||||
...rest,
|
||||
showCancel,
|
||||
confirmText: confirmText ?? translate('common.confirm')
|
||||
}
|
||||
if (showCancel !== false) {
|
||||
modalOptions.cancelText = cancelText ?? translate('common.cancel')
|
||||
}
|
||||
return uni.showModal(modalOptions)
|
||||
}
|
||||
|
||||
/**
|
||||
* 在 setup 中使用 i18n
|
||||
|
||||
@@ -872,6 +872,7 @@ function getUserLocation() {
|
||||
uni.showModal({
|
||||
title: getPermissionText('locationTitle'),
|
||||
content: getPermissionText('locationNeed'),
|
||||
confirmText: getPermissionText('gotIt'),
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { queryById } from '@/config/api/order.js'
|
||||
import { showModalI18n, translate } from '@/utils/i18n.js'
|
||||
|
||||
/**
|
||||
* 订单监控服务
|
||||
@@ -198,11 +199,11 @@ class OrderMonitor {
|
||||
// 如果在订单详情页,页面自己会处理状态变化
|
||||
setTimeout(() => {
|
||||
if (this.currentPage !== 'detail') {
|
||||
uni.showModal({
|
||||
title: '归还成功',
|
||||
content: '风扇已归还成功,剩余押金将退还到您的账户',
|
||||
confirmText: '查看详情',
|
||||
cancelText: '我知道了',
|
||||
showModalI18n({
|
||||
title: translate('order.returnSuccess'),
|
||||
content: translate('order.returnSuccessMessage'),
|
||||
confirmText: translate('order.viewDetails'),
|
||||
cancelText: translate('permission.gotIt'),
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
// 跳转到订单详情页面查看详情
|
||||
|
||||
Reference in New Issue
Block a user