refactor: 国际化文本迁移至全局 locales/messages.js

将组件级 i18n 对象重构为统一由全局 locales/messages.js 管理,确保中英文语言切换时正确显示对应文本。

- 新增 utils/i18n.js 国际化工具函数
- 更新 store/$t.mixin.js 翻译混入逻辑
- 迁移 pkgService、pkgBooking、pkgAccount、pkgExplore、pages 等共 58 个组件的中英文文本至全局消息表
This commit is contained in:
liangjian
2026-07-24 13:43:41 +08:00
parent 445bd850f4
commit 6e721ccc7e
58 changed files with 1810 additions and 4065 deletions

View File

@@ -1,7 +1,7 @@
<template>
<view class="book-page tn-safe-area-inset-bottom">
<tn-nav-bar :isBack="true" :bottomShadow="false" backgroundColor="#F8F9FA">
<view class="tn-text-bold tn-text-xl tn-color-black">{{ t('title') }}</view>
<view class="tn-text-bold tn-text-xl tn-color-black">{{ $tr('预订确认') }}</view>
</tn-nav-bar>
<view class="book-content tn-padding" :style="{paddingTop: vuex_custom_bar_height + 'px', paddingBottom: '180rpx'}">
@@ -13,7 +13,7 @@
</view>
<view class="preview-info tn-flex-1 tn-margin-left tn-flex tn-flex-direction-column tn-flex-row-between">
<view>
<view class="tn-text-sm tn-color-gray">{{ t('bookingFor') }}</view>
<view class="tn-text-sm tn-color-gray">{{ $tr('你正在预约') }}</view>
<view class="tn-text-bold tn-text-lg tn-color-black tn-margin-top-xs clamp-text-2">
{{ displayStyleName }}
</view>
@@ -24,7 +24,7 @@
<view class="tn-flex tn-flex-row-between tn-flex-col-bottom tn-margin-top-sm">
<view class="room-tag tn-text-xs tn-text-bold">{{ displayLocationText }}</view>
<view class="tn-color-black tn-text tn-text-bold">
<text class="tn-text-sm tn-color-gray tn-margin-right-xs">{{ t('deposit') }}</text>$500.00
<text class="tn-text-sm tn-color-gray tn-margin-right-xs">{{ $tr('定金') }}</text>$500.00
</view>
</view>
</view>
@@ -32,15 +32,15 @@
<!-- 填写日期表单 -->
<view class="form-section tn-margin-bottom-xl tn-padding-lg form-card">
<view class="section-title tn-text-bold tn-text-xl tn-margin-bottom-xs">{{ t('checkInDate') }}</view>
<view class="tn-color-gray tn-text-sm tn-margin-bottom-lg">{{ t('checkInDesc') }}</view>
<view class="section-title tn-text-bold tn-text-xl tn-margin-bottom-xs">{{ $tr('填写预订时间') }}</view>
<view class="tn-color-gray tn-text-sm tn-margin-bottom-lg">{{ $tr('支付后会先生成预定单并进入审核,不会直接占用房间资源。') }}</view>
<view class="form-item tn-margin-bottom-lg">
<view class="form-label tn-text-bold">{{ t('startDate') }}</view>
<view class="form-label tn-text-bold">{{ $tr('入住日期 (Check-in)') }}</view>
<picker mode="date" @change="onStartDateChange">
<view class="form-input tn-flex tn-flex-row-between tn-flex-col-center">
<text :class="form.startDate ? 'tn-color-black tn-text-bold' : 'tn-color-gray'">
{{ form.startDate ? form.startDate : t('selectDate') }}
{{ form.startDate ? form.startDate : $tr('请选择日期') }}
</text>
<text class="tn-icon-calendar tn-color-black tn-text-xl"></text>
</view>
@@ -48,11 +48,11 @@
</view>
<view class="form-item tn-margin-bottom-sm">
<view class="form-label tn-text-bold">{{ t('endDate') }}</view>
<view class="form-label tn-text-bold">{{ $tr('离开日期 (Check-out)') }}</view>
<picker mode="date" @change="onEndDateChange" :start="form.startDate">
<view class="form-input tn-flex tn-flex-row-between tn-flex-col-center">
<text :class="form.endDate ? 'tn-color-black tn-text-bold' : 'tn-color-gray'">
{{ form.endDate ? form.endDate : t('selectDate') }}
{{ form.endDate ? form.endDate : $tr('请选择日期') }}
</text>
<text class="tn-icon-calendar tn-color-black tn-text-xl"></text>
</view>
@@ -61,12 +61,12 @@
<view v-if="stayNights > 0" class="tn-margin-top-lg booking-summary">
<view class="summary-row tn-flex tn-flex-row-between">
<text class="tn-color-gray">{{ t('stayNights') }}</text>
<text class="tn-text-bold tn-color-black">{{ stayNights }} {{ t('nightUnit') }}</text>
<text class="tn-color-gray">{{ $tr('入住晚数') }}</text>
<text class="tn-text-bold tn-color-black">{{ stayNights }} {{ $tr('晚') }}</text>
</view>
<view class="summary-row tn-flex tn-flex-row-between tn-margin-top-sm">
<text class="tn-color-gray">{{ t('bookingStatus') }}</text>
<text class="tn-text-bold tn-color-black">{{ t('pendingPayment') }}</text>
<text class="tn-color-gray">{{ $tr('当前状态') }}</text>
<text class="tn-text-bold tn-color-black">{{ $tr('待支付定金') }}</text>
</view>
</view>
</view>
@@ -75,11 +75,11 @@
<!-- 底部固定按钮区 -->
<view class="fixed-bottom-btn-area tn-flex tn-flex-row-between tn-flex-col-center">
<view class="tn-flex tn-flex-direction-column">
<view class="tn-text-sm tn-color-gray">{{ t('deposit') }}</view>
<view class="tn-text-sm tn-color-gray">{{ $tr('定金') }}</view>
<view class="tn-text-bold tn-text-xl" style="color: $brand-primary;">$500.00</view>
</view>
<view class="custom-btn btn-dark" style="width: 60%; height: 100rpx;" @click="submitBooking" :class="{ 'btn-disabled': isSubmitting }">
<text class="tn-text-bold tn-text-lg">{{ isSubmitting ? (language === 'zh' ? '处理中...' : 'Processing...') : t('submitOrder') }}</text>
<text class="tn-text-bold tn-text-lg">{{ isSubmitting ? (language === 'zh' ? '处理中...' : 'Processing...') : $tr('进入支付页') }}</text>
</view>
</view>
@@ -100,40 +100,6 @@ export default {
form: {
startDate: '',
endDate: ''
},
i18n: {
zh: {
title: '预订确认',
bookingFor: '你正在预约',
deposit: '定金',
checkInDate: '填写预订时间',
checkInDesc: '支付后会先生成预定单并进入审核,不会直接占用房间资源。',
startDate: '入住日期 (Check-in)',
endDate: '离开日期 (Check-out)',
selectDate: '请选择日期',
submitOrder: '进入支付页',
stayNights: '入住晚数',
nightUnit: '晚',
bookingStatus: '当前状态',
pendingPayment: '待支付定金',
roomTypeLabel: '房型:'
},
en: {
title: 'Booking Confirm',
bookingFor: 'Booking For',
deposit: 'Deposit',
checkInDate: 'Booking Period',
checkInDesc: 'Payment will create a booking order first, without occupying room inventory.',
startDate: 'Check-in Date',
endDate: 'Check-out Date',
selectDate: 'Select Date',
submitOrder: 'Go To Payment',
stayNights: 'Stay Nights',
nightUnit: 'nights',
bookingStatus: 'Status',
pendingPayment: 'Deposit Pending',
roomTypeLabel: 'Room Type: '
}
}
}
},
@@ -159,7 +125,7 @@ export default {
const areaText = this.language === 'en'
? (this.applyData.roomAreaEnDisplay || compactEnglishText(this.applyData.roomAreaEn || this.applyData.roomArea || '', 28))
: (this.applyData.roomArea || this.applyData.roomAreaEn || '')
return [roomTypeText ? `${this.t('roomTypeLabel')}${roomTypeText}` : '', areaText].filter(Boolean).join(' | ')
return [roomTypeText ? `${this.$tr('房型:')}${roomTypeText}` : '', areaText].filter(Boolean).join(' | ')
},
displayLocationText() {
if (!this.applyData) {
@@ -200,9 +166,6 @@ export default {
this.redirectIfBookingUnavailable()
},
methods: {
t(key) {
return this.$tm('pkgBooking.book.book', key)
},
redirectIfBookingUnavailable() {
const session = getSessionSnapshot()
if (!session.isLogin) {