From ee8dd2df44275fbefa0d449bf08ba30c51c5c620 Mon Sep 17 00:00:00 2001 From: moyayu <1623253835@qq.com> Date: Wed, 22 Apr 2026 13:34:29 +0800 Subject: [PATCH] refactor(i18n): move react-i18next bundle under subpage and trim main usage Move src/i18n (index, instance, app-config-t, locales) to src/subpage/i18n so the implementation lives with the subpage package instead of a root-level i18n folder. Replace react-i18next usage with inline Chinese strings on touched auth flows, member index, cart, and validate helpers to avoid pulling i18next JSON into those bundles. Keep legacy lang switching: Taro.$changeLang still bootstraps subpages/i18n JSON; sync to i18next uses dynamic import of @/subpage/i18n/instance from lang/index.js. Also updates SpPage, store, marketing/coupon/package/buy-toolbar, hot-zone widget, app.config comment, and extra keys in subpages/i18n/lang/index.json where needed. Made-with: Cursor --- src/app.config.js | 6 +- src/components/sp-page/index.js | 3 +- src/lang/index.js | 49 ++------- .../pages/member/comps/comp-activity-item.js | 76 ++++++------- src/pages/cart/espier-index.js | 38 +++---- src/pages/home/wgts/imghot-zone/index.jsx | 20 ++-- src/{ => subpage}/i18n/app-config-t.js | 0 src/{ => subpage}/i18n/index.js | 0 src/{ => subpage}/i18n/instance.js | 0 src/{ => subpage}/i18n/locales/ar.json | 0 src/{ => subpage}/i18n/locales/en.json | 0 src/{ => subpage}/i18n/locales/zh-CN.json | 0 .../auth/comps/comp-password-input.js | 4 +- src/subpages/auth/forgotpwd-email.js | 16 ++- src/subpages/auth/forgotpwd.js | 34 +++--- src/subpages/auth/login.js | 101 ++++++++---------- src/subpages/auth/reg.js | 75 ++++++------- src/subpages/i18n/lang/index.json | 54 ++++++++++ src/subpages/item/comps/comp-buytoolbar.js | 2 +- .../marketing/comps/comp-packageitem.js | 10 +- src/subpages/marketing/coupon-center.js | 6 +- src/subpages/member/index.js | 27 +++-- src/subpages/member/index.scss | 3 +- src/subpages/store/index.js | 11 -- src/utils/validate.js | 5 +- 25 files changed, 267 insertions(+), 273 deletions(-) rename src/{ => subpage}/i18n/app-config-t.js (100%) rename src/{ => subpage}/i18n/index.js (100%) rename src/{ => subpage}/i18n/instance.js (100%) rename src/{ => subpage}/i18n/locales/ar.json (100%) rename src/{ => subpage}/i18n/locales/en.json (100%) rename src/{ => subpage}/i18n/locales/zh-CN.json (100%) diff --git a/src/app.config.js b/src/app.config.js index 62de5aa2e..1b62a46af 100644 --- a/src/app.config.js +++ b/src/app.config.js @@ -2,7 +2,7 @@ * Copyright © ShopeX (http://www.shopex.cn). All rights reserved. * See LICENSE file for license details. */ -import { appConfigT } from '@/i18n/app-config-t' +// import { appConfigT } from '@/subpage/i18n/app-config-t' const config = { pages: [ @@ -479,7 +479,7 @@ const config = { ], permission: { 'scope.userLocation': { - desc: appConfigT('95285d68.93f311') + desc: '您的位置信息将用于定位附近门店' } }, // usingComponents: { @@ -488,7 +488,7 @@ const config = { window: { 'backgroundTextStyle': 'light', 'navigationBarBackgroundColor': '#fff', - 'navigationBarTitleText': appConfigT('95285d68.0ed510'), + 'navigationBarTitleText': '小程序', 'navigationBarTextStyle': 'black' }, plugins: { diff --git a/src/components/sp-page/index.js b/src/components/sp-page/index.js index de86f31b1..aaa6f23b0 100644 --- a/src/components/sp-page/index.js +++ b/src/components/sp-page/index.js @@ -155,12 +155,13 @@ const SpPage = memo( let _navigationRSpace = 0 // 导航栏右间距 const { screenHeight, windowWidth, windowHeight } = Taro.getWindowInfo() const [absolutePath] = router?.path.split('?') + const forceShowBack = String(router?.params?.showBack || '') === '1' // 小程序/支付宝:按页面 config 是否 custom;H5:有 pageConfig 或 immersive 时也使用自定义顶栏以支持相同顶部样式 const custom_navigation = isWeixin || isAlipay ? navigationStyle === 'custom' : isWeb && !!(props.pageConfig || props.immersive) - const _btnReturn = pages.length > 1 && !TAB_PAGES.includes(absolutePath) + const _btnReturn = pages.length > 1 && (!TAB_PAGES.includes(absolutePath) || forceShowBack) const _btnHome = pages.length == 1 && !TAB_PAGES.includes(absolutePath) if (isWeixin || isAlipay) { const menuButton = Taro.getMenuButtonBoundingClientRect() diff --git a/src/lang/index.js b/src/lang/index.js index 5c3dd6812..61275d294 100644 --- a/src/lang/index.js +++ b/src/lang/index.js @@ -3,7 +3,6 @@ * See LICENSE file for license details. */ import Taro from '@tarojs/taro' -import { syncI18nLanguage } from '@/i18n/instance' class Lang { constructor() { @@ -11,7 +10,6 @@ class Lang { } init() { - const self = this // 定义翻译函数 let $t = function (key, val, nameSpace) { // 获取指定命名空间下的语言包 @@ -67,43 +65,6 @@ class Lang { // 返回语言对象 return langObj } - - /** - * 必须在首屏即可用:`setLanguagePackage` 在 useLaunch 里异步执行, - * 用户在语言包就绪前进「设置 → 切换语言」会导致 Taro.$changeLang 未定义。 - */ - Taro.$changeLang = (lang) => { - const apply = () => { - globalThis._localStorage.setItem('lang', lang) - globalThis.$t.locale(globalThis.langMap[lang], 'lang') - if (Taro.eventCenter) { - Taro.eventCenter.trigger('languageChanged', { lang, langMap: globalThis.langMap[lang] }) - } - Promise.resolve(syncI18nLanguage(lang)).catch(() => {}) - } - - if ( - globalThis.langMap && - typeof globalThis.langMap === 'object' && - Object.keys(globalThis.langMap).length > 0 - ) { - apply() - return - } - import('@/subpages/i18n/index') - .then(() => { - const langJSON = Taro['langJSON'] - if (!langJSON) { - console.error('[Lang] Taro.langJSON missing, cannot switch language') - return - } - self.setLanguagePackage(langJSON) - apply() - }) - .catch((e) => { - console.error('[Lang] Failed to load language bundle', e) - }) - } } setLanguagePackage(langJSON) { @@ -185,7 +146,15 @@ class Lang { } // 根据当前语言设置翻译函数的语言包 globalThis.$t.locale(globalThis.langMap[lang], 'lang') - Promise.resolve(syncI18nLanguage(lang)).catch(() => {}) + + Taro.$changeLang = (lang) => { + globalThis._localStorage.setItem('lang', lang) + globalThis.$t.locale(globalThis.langMap[lang], 'lang') + // 触发语言变化事件,让其他地方能够监听到 + if (Taro.eventCenter) { + Taro.eventCenter.trigger('languageChanged', { lang, langMap: globalThis.langMap[lang] }) + } + } } } diff --git a/src/marketing/pages/member/comps/comp-activity-item.js b/src/marketing/pages/member/comps/comp-activity-item.js index 56c14587f..b9101cd41 100644 --- a/src/marketing/pages/member/comps/comp-activity-item.js +++ b/src/marketing/pages/member/comps/comp-activity-item.js @@ -86,46 +86,50 @@ function CompActivityItem(props) { {reason} )} - + {isActivity && 会员免费} - {isActivity && recordId ? ( - { - e.stopPropagation() - onViewRecords(info) - }} - > - 查看报名记录 - - ) : null} - {actionEdit && !isActivity && ( - handleBtnClick(e, 'reFill')} - > - 重新填写 - - )} - {!isActivity && actionApply && ( - handleBtnClick(e, 'sign')}> - 立即报名 - - )} + {isActivity && recordId ? ( + { + e.stopPropagation() + onViewRecords(info) + }} + > + 查看报名记录 + + ) : null} + {actionEdit && !isActivity && ( + handleBtnClick(e, 'reFill')} + > + 重新填写 + + )} + {!isActivity && actionApply && ( + handleBtnClick(e, 'sign')} + > + 立即报名 + + )} - {isActivity && ( - handleBtnClick(e, 'sign')} - > - 立即报名 - - )} - + {isActivity && ( + handleBtnClick(e, 'sign')} + > + 立即报名 + + )} + + ) diff --git a/src/pages/cart/espier-index.js b/src/pages/cart/espier-index.js index 3a06c9f46..80bac4db6 100644 --- a/src/pages/cart/espier-index.js +++ b/src/pages/cart/espier-index.js @@ -3,7 +3,7 @@ * See LICENSE file for license details. */ import Taro, { getCurrentInstance, useDidShow } from '@tarojs/taro' -import React, { useEffect, useState, useMemo } from 'react' +import React, { useEffect } from 'react' import { useSelector, useDispatch } from 'react-redux' import { View, Text, ScrollView } from '@tarojs/components' import { AtButton } from 'taro-ui' @@ -12,7 +12,6 @@ import qs from 'qs' import api from '@/api' import doc from '@/doc' import { navigateTo, pickBy, classNames, throttle } from '@/utils' -import { useTranslation, $t, ti } from '@/i18n' import { useLogin, useLocation, useDebounce } from '@/hooks' import { fetchCartList, deleteCartItem, updateCartItemNum, updateCount } from '@/store/slices/cart' import { updatePurchaseShareInfo, updateInviteCode } from '@/store/slices/purchase' @@ -45,7 +44,6 @@ const initialState = { } function CartIndex() { - useTranslation() const { updateAddress } = useLocation() const { shopInfo = {} } = useSelector((state) => state.shop) @@ -224,11 +222,11 @@ function CartIndex() { const onDeleteCartGoodsItem = async ({ cart_id }) => { const res = await Taro.showModal({ - title: $t('61e2d21a.02d981'), - content: $t('61e2d21a.a4936e'), + title: '提示', + content: '将当前商品移出购物车?', showCancel: true, - cancelText: $t('61e2d21a.625fb2'), - confirmText: $t('61e2d21a.e83a25'), + cancelText: '取消', + confirmText: '确认', confirmColor: colorPrimary }) if (!res.confirm) return @@ -303,9 +301,9 @@ function CartIndex() { )} {!isLogin && ( - {$t('f9ef9536.29b36a')} + 授权登录后同步购物车的商品 {}}> - {$t('f9ef9536.d72d86')} + 授权登录 )} @@ -319,7 +317,7 @@ function CartIndex() { - {all_item.shop_name || $t('f9ef9536.491c0c')} + {all_item.shop_name || '自营'} {/** 店铺商品开始 */} @@ -344,9 +342,7 @@ function CartIndex() { }) } > - - {$t('f9ef9536.1687b1')} - + 换购 {discount_desc.info} - {$t('f9ef9536.5ba3e7')} + 去选择 @@ -426,7 +422,7 @@ function CartIndex() { @@ -435,12 +431,12 @@ function CartIndex() { - {$t('f9ef9536.7b2864')} + 合计: {all_item.discount_fee > 0 && ( - {$t('f9ef9536.1784cf')} + 共优惠: handleCheckout(all_item)} > - {ti('f9ef9536.605bad', [all_item.cart_total_num])} + {`结算(${all_item.cart_total_num})`} @@ -468,7 +464,7 @@ function CartIndex() { {invalidCart.length > 0 && ( - {$t('f9ef9536.31a812')} + 已失效商品 {invalidCart.map((sitem, sindex) => ( @@ -492,9 +488,9 @@ function CartIndex() { )} {validCart.length == 0 && invalidCart.length == 0 && ( - + - {$t('61e2d21a.aed876')} + 去选购 )} diff --git a/src/pages/home/wgts/imghot-zone/index.jsx b/src/pages/home/wgts/imghot-zone/index.jsx index 657021e4a..178542826 100644 --- a/src/pages/home/wgts/imghot-zone/index.jsx +++ b/src/pages/home/wgts/imghot-zone/index.jsx @@ -92,16 +92,16 @@ function WgtImgHotZone(props) { distributor_id }) - if (item.id === 'customerService') { - return ( -