修改国际版本

This commit is contained in:
2026-06-12 16:08:00 +08:00
parent af758a0ccc
commit 836cdaf2dc
38 changed files with 449 additions and 145 deletions
+54
View File
@@ -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
+1
View File
@@ -872,6 +872,7 @@ function getUserLocation() {
uni.showModal({
title: getPermissionText('locationTitle'),
content: getPermissionText('locationNeed'),
confirmText: getPermissionText('gotIt'),
showCancel: false
});
}
+6 -5
View File
@@ -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) {
// 跳转到订单详情页面查看详情