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

@@ -16,17 +16,17 @@
<tn-popup v-model="showPopup" mode="bottom" length="72%" :borderRadius="32" :closeBtn="true">
<view class="popup-content">
<view class="popup-header">
<text class="popup-title">{{ t('popupTitle') }}</text>
<text class="popup-title">{{ $tr('选择意向楼栋') }}</text>
</view>
<scroll-view scroll-y class="building-list-scroll">
<view v-if="isLoading" class="loading-state tn-padding-xl tn-text-center">
<tn-loading mode="circle"></tn-loading>
<view class="tn-margin-top-sm tn-color-gray">{{ t('loadingText') }}</view>
<view class="tn-margin-top-sm tn-color-gray">{{ $tr('楼栋加载中...') }}</view>
</view>
<view v-else-if="!buildingList.length" class="empty-state tn-padding-xl tn-text-center">
<text class="tn-color-gray">{{ t('emptyText') }}</text>
<text class="tn-color-gray">{{ $tr('暂无可选楼栋') }}</text>
</view>
<view v-else class="building-list">
@@ -97,7 +97,7 @@ export default {
return this.$getLanguage ? this.$getLanguage() : 'zh'
},
placeholderText() {
return this.areaCode ? this.t('selectBuilding') : this.t('selectAreaFirst')
return this.areaCode ? this.$tr('请选择楼栋') : this.$tr('请先选择区域')
}
},
watch: {
@@ -120,13 +120,10 @@ export default {
this.loadData()
},
methods: {
t(key, params) {
return this.$tm('pkgService.submit_request.components.BuildingSelector', key, params)
},
handleOpen() {
if (!this.areaCode) {
uni.showToast({
title: this.t('selectAreaFirst'),
title: this.$tr('请先选择区域'),
icon: 'none'
})
return
@@ -189,7 +186,7 @@ export default {
this.buildingList = []
this.selectedBuilding = null
uni.showToast({
title: this.t('loadFailed'),
title: this.$tr('楼栋列表加载失败'),
icon: 'none'
})
})

View File

@@ -8,7 +8,7 @@
</view>
</picker>
</view>
<view class="date-divider">{{ t('dateDivider') }}</view>
<view class="date-divider">{{ $tr('至') }}</view>
<view class="date-item">
<view class="date-label">{{ resolvedEndLabel }}</view>
<picker mode="date" @change="onEndChange">
@@ -23,22 +23,6 @@
<script>
export default {
name: 'DateRangeSelector',
i18n: {
zh: {
startLabel: '预计入住',
endLabel: '预计离开',
startPlaceholder: '请选择入住日期',
endPlaceholder: '请选择离开日期',
dateDivider: '至'
},
en: {
startLabel: 'Expected Check-in',
endLabel: 'Expected Check-out',
startPlaceholder: 'Select check-in date',
endPlaceholder: 'Select check-out date',
dateDivider: 'to'
}
},
props: {
start: {
type: String,
@@ -67,22 +51,19 @@ export default {
},
computed: {
resolvedStartLabel() {
return this.startLabel || this.t('startLabel')
return this.startLabel || this.$tr('预计入住')
},
resolvedEndLabel() {
return this.endLabel || this.t('endLabel')
return this.endLabel || this.$tr('预计离开')
},
resolvedStartPlaceholder() {
return this.startPlaceholder || this.t('startPlaceholder')
return this.startPlaceholder || this.$tr('请选择入住日期')
},
resolvedEndPlaceholder() {
return this.endPlaceholder || this.t('endPlaceholder')
return this.endPlaceholder || this.$tr('请选择离开日期')
}
},
methods: {
t(key) {
return this.$tm('pkgService.submit_request.components.DateRangeSelector', key)
},
onStartChange(e) {
this.$emit('update:start', e.detail.value)
},
@@ -128,7 +109,7 @@ export default {
font-size: 28rpx;
color: #1A2B4C;
font-weight: 600;
&.is-empty {
color: #CBD5E1;
font-weight: normal;

View File

@@ -15,17 +15,17 @@
<tn-popup v-model="showPopup" mode="bottom" length="72%" :borderRadius="32" :closeBtn="true">
<view class="popup-content">
<view class="popup-header">
<text class="popup-title">{{ t('popupTitle') }}</text>
<text class="popup-title">{{ $tr('选择意向楼层') }}</text>
</view>
<scroll-view scroll-y class="floor-list-scroll">
<view v-if="isLoading" class="loading-state tn-padding-xl tn-text-center">
<tn-loading mode="circle"></tn-loading>
<view class="tn-margin-top-sm tn-color-gray">{{ t('loadingText') }}</view>
<view class="tn-margin-top-sm tn-color-gray">{{ $tr('楼层加载中...') }}</view>
</view>
<view v-else-if="!floorList.length" class="empty-state tn-padding-xl tn-text-center">
<text class="tn-color-gray">{{ t('emptyText') }}</text>
<text class="tn-color-gray">{{ $tr('暂无可选楼层') }}</text>
</view>
<view v-else class="floor-list">
@@ -34,7 +34,7 @@
:class="{ 'is-active': !selectedFloor }"
@click="handleClear"
>
<text class="floor-name">{{ t('clearSelection') }}</text>
<text class="floor-name">{{ $tr('不选择') }}</text>
<text v-if="!selectedFloor" class="tn-icon-success-circle-fill floor-check"></text>
</view>
<view
@@ -133,7 +133,7 @@ export default {
return this.$getLanguage ? this.$getLanguage() : 'zh'
},
placeholderText() {
return this.t('selectFloor')
return this.$tr('请选择楼层')
}
},
watch: {
@@ -148,9 +148,6 @@ export default {
this.loadData()
},
methods: {
t(key, params) {
return this.$tm('pkgService.submit_request.components.FloorSelector', key, params)
},
handleOpen() {
this.showPopup = true
this.loadData()
@@ -176,7 +173,7 @@ export default {
this.floorList = []
this.selectedFloor = null
uni.showToast({
title: this.t('loadFailed'),
title: this.$tr('楼层列表加载失败'),
icon: 'none'
})
})

View File

@@ -3,7 +3,7 @@
<view class="selector-header tn-flex tn-flex-row-between tn-flex-col-center" @click="openSelector">
<view class="selected-info">
<view class="selected-name tn-text-ellipsis" :class="{ 'is-empty': !selectedRoomType }">
{{ selectedRoomType ? getRoomTypeDisplayName(selectedRoomType) : t('selectRoomType') }}
{{ selectedRoomType ? getRoomTypeDisplayName(selectedRoomType) : $tr('请选择意向房型') }}
</view>
<view class="selected-area tn-text-ellipsis" v-if="selectedArea">
{{ getAreaDisplayName(selectedArea) }}
@@ -15,17 +15,17 @@
<tn-popup v-model="showPopup" mode="bottom" length="80%" :borderRadius="32" :closeBtn="true">
<view class="popup-content">
<view class="popup-header">
<text class="popup-title">{{ t('popupTitle') }}</text>
<text class="popup-title">{{ $tr('选择意向房型') }}</text>
</view>
<scroll-view scroll-y class="area-list-scroll">
<view v-if="isLoading" class="loading-state tn-padding-xl tn-text-center">
<tn-loading mode="circle"></tn-loading>
<view class="tn-margin-top-sm tn-color-gray">{{ t('loadingRoomTypes') }}</view>
<view class="tn-margin-top-sm tn-color-gray">{{ $tr('房型加载中...') }}</view>
</view>
<view v-else-if="!displayAreaList.length" class="empty-state tn-padding-xl tn-text-center">
<text class="tn-color-gray">{{ t('emptyRoomTypes') }}</text>
<text class="tn-color-gray">{{ $tr('暂无可选房型') }}</text>
</view>
<view v-else class="area-group" v-for="(area, index) in displayAreaList" :key="area.code">
@@ -45,7 +45,7 @@
@click="handleSelect(area, room)"
>
<view class="room-name tn-text-ellipsis">{{ getRoomTypeDisplayName(room) }}</view>
<view class="room-price" v-if="room.price">¥{{ getPriceValue(room.price) }}{{ t('priceUnit') }}</view>
<view class="room-price" v-if="room.price">¥{{ getPriceValue(room.price) }}{{ $tr('/月') }}</view>
</view>
</view>
</view>
@@ -118,9 +118,6 @@ export default {
this.loadData()
},
methods: {
t(key) {
return this.$translate(this.i18n, key)
},
openSelector() {
this.showPopup = true
this.loadData()
@@ -148,7 +145,7 @@ export default {
})
.catch((e) => {
console.error('load room types error', e)
uni.showToast({ title: this.t('loadFailed'), icon: 'none' })
uni.showToast({ title: this.$tr('房型列表加载失败'), icon: 'none' })
})
.finally(() => {
this.isLoading = false

View File

@@ -11,23 +11,13 @@
{{ item.value }}
</view>
</view>
<view v-else class="empty-tips">{{ loading ? t('loadingText') : resolvedEmptyText }}</view>
<view v-else class="empty-tips">{{ loading ? $tr('标签加载中...') : resolvedEmptyText }}</view>
</view>
</template>
<script>
export default {
name: 'TagSelector',
i18n: {
zh: {
loadingText: '标签加载中...',
emptyText: '暂无标签'
},
en: {
loadingText: 'Loading tags...',
emptyText: 'No tags available'
}
},
props: {
value: {
type: Array,
@@ -48,13 +38,10 @@ export default {
},
computed: {
resolvedEmptyText() {
return this.emptyText || this.t('emptyText')
return this.emptyText || this.$tr('暂无标签')
}
},
methods: {
t(key, params) {
return this.$tm('pkgService.submit_request.components.TagSelector', key, params)
},
toggleTag(key) {
const currentList = [...this.value]
const index = currentList.indexOf(key)

View File

@@ -44,22 +44,22 @@
</view>
<view v-if="showPreferenceSelectors" class="form-item tn-margin-top">
<view class="form-label">{{ t('hobbyLabel') }}</view>
<view class="form-label">{{ $tr('兴趣爱好') }}</view>
<tag-selector
v-model="form.hobbiesAndInterestsTagKeys"
:options="hobbyOptions"
:loading="dictLoading"
:emptyText="t('emptyHobbyTags')"
:emptyText="$tr('暂无兴趣爱好标签')"
/>
</view>
<view v-if="showPreferenceSelectors" class="form-item tn-margin-top">
<view class="form-label">{{ t('lifestyleLabel') }}</view>
<view class="form-label">{{ $tr('生活习惯') }}</view>
<tag-selector
v-model="form.lifestyleHabitsTagKeys"
:options="lifestyleOptions"
:loading="dictLoading"
:emptyText="t('emptyLifestyleTags')"
:emptyText="$tr('暂无生活习惯标签')"
/>
</view>
@@ -76,12 +76,12 @@
</view>
<view class="form-item tn-margin-top">
<view class="form-label">{{ t('remarkLabel') }}</view>
<view class="form-label">{{ $tr('补充说明') }}</view>
<textarea class="form-textarea" :placeholder="remarkPlaceholder" v-model="form.remark"></textarea>
</view>
<view v-if="!showFloatingSubmitBtn" class="submit-btn btn-primary tn-margin-top-xl" :class="{ 'submit-btn--disabled': isSubmitting }" @click="submitRequest">
<text class="tn-text-bold">{{ isSubmitting ? t('submitting') : primaryActionText }}</text>
<text class="tn-text-bold">{{ isSubmitting ? $tr('提交中...') : primaryActionText }}</text>
</view>
</view>
</view>
@@ -91,7 +91,7 @@
<view v-if="showFloatingSubmitBtn" class="floating-submit-bar">
<view class="floating-submit-bar__inner">
<view class="submit-btn btn-primary" :class="{ 'submit-btn--disabled': isSubmitting }" @click="submitRequest">
<text class="tn-text-bold">{{ isSubmitting ? t('submitting') : primaryActionText }}</text>
<text class="tn-text-bold">{{ isSubmitting ? $tr('提交中...') : primaryActionText }}</text>
</view>
</view>
</view>
@@ -594,81 +594,7 @@ export default {
lifestyleOptions: [],
form: createDefaultForm(),
scrollTop: 0,
lastAutoRemark: '',
i18n: {
zh: {
hobbyLabel: '兴趣爱好',
emptyHobbyTags: '暂无兴趣爱好标签',
lifestyleLabel: '生活习惯',
emptyLifestyleTags: '暂无生活习惯标签',
remarkLabel: '补充说明',
submitting: '提交中...',
roomTypeApplyTitle: '房型申请',
roomTypeApplyDesc: '请确认房型、区域、偏好标签和租期信息后提交申请。',
roomTypeApplyBlockTitle: '房型申请信息',
roomTypeApplyBlockDesc: '已接入真实申请单接口,支持带出房型与区域编码后直接提交。',
applyRemarkPlaceholder: '请输入您的申请补充说明',
submitRoomTypeApply: '提交房型申请',
applyRoomType: '申请房型',
leaseRange: '租期时间',
expectedCheckin: '预计入住',
expectedCheckout: '预计离开',
selectCheckinDate: '请选择入住日期',
selectCheckoutDate: '请选择离开日期',
currentRoom: '当前房间',
areaLabel: '所属区域',
referencePrice: '参考价格',
paymentMethod: '支付方式',
applicationType: '申请类型',
stayApplyDefaultTitle: '入住申请',
stayApplyDefaultDesc: '请填写您的入住意向、生活偏好与预计租期后提交申请单。',
sourceDefaultDesc: '请填写您的入住意向、租期和补充说明。',
tagLoadFailed: '偏好标签加载失败',
remarkRequired: '请输入补充说明',
applicationInfo: '申请信息',
selectDateStart: '请选择{label}',
selectDateEnd: '请选择{label}',
dateCannotBefore: '{endLabel}不能早于{startLabel}',
submitSuccess: '申请单提交成功',
submitFailed: '申请单提交失败'
},
en: {
hobbyLabel: 'Hobbies',
emptyHobbyTags: 'No hobby tags',
lifestyleLabel: 'Lifestyle Habits',
emptyLifestyleTags: 'No lifestyle tags',
remarkLabel: 'Additional Notes',
submitting: 'Submitting...',
roomTypeApplyTitle: 'Room Type Application',
roomTypeApplyDesc: 'Confirm the room type, area, preference tags, and lease period before submitting.',
roomTypeApplyBlockTitle: 'Application Details',
roomTypeApplyBlockDesc: 'The live application API is connected and can submit with room and area codes.',
applyRemarkPlaceholder: 'Enter your additional notes',
submitRoomTypeApply: 'Submit Application',
applyRoomType: 'Requested Room Type',
leaseRange: 'Lease Period',
expectedCheckin: 'Expected Check-in',
expectedCheckout: 'Expected Checkout',
selectCheckinDate: 'Select check-in date',
selectCheckoutDate: 'Select checkout date',
currentRoom: 'Current Room',
areaLabel: 'Area',
referencePrice: 'Reference Price',
paymentMethod: 'Payment Method',
applicationType: 'Application Type',
stayApplyDefaultTitle: 'Stay Application',
stayApplyDefaultDesc: 'Fill in your stay intention, preferences, and lease period before submission.',
sourceDefaultDesc: 'Fill in your stay intention, lease period, and notes.',
tagLoadFailed: 'Failed to load preference tags',
remarkRequired: 'Please enter additional notes',
applicationInfo: 'Application Details',
selectDateStart: 'Please select {label}',
selectDateEnd: 'Please select {label}',
dateCannotBefore: '{endLabel} cannot be earlier than {startLabel}',
submitSuccess: 'Application submitted',
submitFailed: 'Failed to submit application'
}
}
lastAutoRemark: ''
}
},
computed: {
@@ -709,52 +635,52 @@ export default {
pageTitle() {
if (this.isRoomTypeApply) {
return this.language === 'en'
? compactEnglishText(this.t('roomTypeApplyTitle'), 22)
: this.t('roomTypeApplyTitle')
? compactEnglishText(this.$tr('房型申请'), 22)
: this.$tr('房型申请')
}
return this.getBusinessText('titleShort')
|| this.getBusinessText('title')
|| this.getLocalizedSourceText('title')
|| this.t('stayApplyDefaultTitle')
|| this.$tr('入住申请')
},
pageDesc() {
if (this.isRoomTypeApply) {
return this.language === 'en'
? compactEnglishText(this.t('roomTypeApplyDesc'), 96)
: this.t('roomTypeApplyDesc')
? compactEnglishText(this.$tr('请确认房型、区域、偏好标签和租期信息后提交申请。'), 96)
: this.$tr('请确认房型、区域、偏好标签和租期信息后提交申请。')
}
const text = this.getBusinessText('desc') || this.getLocalizedSourceText('desc') || this.t('stayApplyDefaultDesc')
const text = this.getBusinessText('desc') || this.getLocalizedSourceText('desc') || this.$tr('请填写您的入住意向、生活偏好与预计租期后提交申请单。')
return this.language === 'en' ? compactEnglishText(text, 96) : text
},
formBlockTitle() {
if (this.isRoomTypeApply) {
return this.t('roomTypeApplyBlockTitle')
return this.$tr('房型申请信息')
}
return this.getBusinessText('formBlockTitle') || this.t('applicationInfo')
return this.getBusinessText('formBlockTitle') || this.$tr('申请信息')
},
formBlockDesc() {
if (this.isRoomTypeApply) {
return this.t('roomTypeApplyBlockDesc')
return this.$tr('已接入真实申请单接口,支持带出房型与区域编码后直接提交。')
}
return this.getBusinessText('formBlockDesc') || this.t('stayApplyDefaultDesc')
return this.getBusinessText('formBlockDesc') || this.$tr('请填写您的入住意向、生活偏好与预计租期后提交申请单。')
},
remarkPlaceholder() {
if (this.isRoomTypeApply) {
return this.t('applyRemarkPlaceholder')
return this.$tr('请输入您的申请补充说明')
}
return this.getBusinessText('remarkPlaceholder') || this.t('remarkRequired')
return this.getBusinessText('remarkPlaceholder') || this.$tr('请输入补充说明')
},
primaryActionText() {
if (this.isRoomTypeApply) {
return this.language === 'en'
? compactEnglishText(this.t('submitRoomTypeApply'), 24)
: this.t('submitRoomTypeApply')
? compactEnglishText(this.$tr('提交房型申请'), 24)
: this.$tr('提交房型申请')
}
const text = this.getBusinessText('primaryActionText') || this.t('submitApplicationFallback')
const text = this.getBusinessText('primaryActionText') || this.$tr('提交申请')
return this.language === 'en' ? compactEnglishText(text, 24) : text
},
roomTypeLabel() {
return this.getBusinessText('roomTypeLabel') || this.t('applyRoomType')
return this.getBusinessText('roomTypeLabel') || this.$tr('申请房型')
},
pageBottomPadding() {
return this.showFloatingSubmitBtn ? '220rpx' : '60rpx'
@@ -763,7 +689,7 @@ export default {
return this.isRoomTypeApply
},
floorLabel() {
return this.getBusinessText('floorLabel') || this.t('floorLabel')
return this.getBusinessText('floorLabel') || this.$tr('楼层')
},
showRoomTypeSelector() {
if (this.isRoomTypeApply) {
@@ -790,19 +716,19 @@ export default {
return this.businessConfig ? this.businessConfig.showDateRange !== false : true
},
dateRangeLabel() {
return this.getBusinessText('dateRangeLabel') || this.t('leaseRange')
return this.getBusinessText('dateRangeLabel') || this.$tr('租期时间')
},
dateRangeStartLabel() {
return this.getBusinessText('dateRangeStartLabel') || this.t('expectedCheckin')
return this.getBusinessText('dateRangeStartLabel') || this.$tr('预计入住')
},
dateRangeEndLabel() {
return this.getBusinessText('dateRangeEndLabel') || this.t('expectedCheckout')
return this.getBusinessText('dateRangeEndLabel') || this.$tr('预计离开')
},
dateRangeStartPlaceholder() {
return this.getBusinessText('dateRangeStartPlaceholder') || this.t('selectCheckinDate')
return this.getBusinessText('dateRangeStartPlaceholder') || this.$tr('请选择入住日期')
},
dateRangeEndPlaceholder() {
return this.getBusinessText('dateRangeEndPlaceholder') || this.t('selectCheckoutDate')
return this.getBusinessText('dateRangeEndPlaceholder') || this.$tr('请选择离开日期')
}
},
watch: {
@@ -839,9 +765,6 @@ export default {
this.loadDictOptions()
},
methods: {
t(key, params) {
return this.$tm('pkgService.submit_request.submit_request', key, params)
},
decodeRouteText(value, fallback = '') {
if (value === undefined || value === null || value === '') {
return fallback
@@ -1000,7 +923,7 @@ export default {
.catch((error) => {
console.error('load application dict options failed', error)
uni.showToast({
title: this.t('tagLoadFailed'),
title: this.$tr('偏好标签加载失败'),
icon: 'none'
})
})
@@ -1038,20 +961,20 @@ export default {
validateForm() {
if (this.showDateRange) {
if (!this.form.start) {
return this.t('selectDateStart', { label: this.dateRangeStartLabel })
return this.$tr('请选择{label}', { label: this.dateRangeStartLabel })
}
if (!this.form.end) {
return this.t('selectDateEnd', { label: this.dateRangeEndLabel })
return this.$tr('请选择{label}', { label: this.dateRangeEndLabel })
}
if (new Date(this.form.end).getTime() < new Date(this.form.start).getTime()) {
return this.t('dateCannotBefore', {
return this.$tr('{endLabel}不能早于{startLabel}', {
endLabel: this.dateRangeEndLabel,
startLabel: this.dateRangeStartLabel
})
}
}
if (!this.form.remark.trim()) {
return this.t('remarkRequired')
return this.$tr('请输入补充说明')
}
return ''
},
@@ -1084,7 +1007,7 @@ export default {
this.isSubmitting = true
uni.showLoading({
title: this.t('submitting')
title: this.$tr('提交中...')
})
const payload = this.buildSubmitPayload()
@@ -1096,7 +1019,7 @@ export default {
}
uni.hideLoading()
uni.showToast({
title: this.t('submitSuccess'),
title: this.$tr('申请单提交成功'),
icon: 'success'
})
@@ -1111,7 +1034,7 @@ export default {
console.error('submit application form failed', error)
uni.hideLoading()
uni.showToast({
title: (error && (error.message || error.msg)) || this.t('submitFailed'),
title: (error && (error.message || error.msg)) || this.$tr('申请单提交失败'),
icon: 'none'
})
})