refactor(i18n): 全工程面向国际用户与全球现代商务重构,彻底清理出海跨境等单向视角表达并对齐自动化测试

这个提交包含在:
wikiboss
2026-09-21 15:24:36 +08:00
父节点 ad9df7a7a4
当前提交 17882ca1cb
共有 135 个文件被更改,包括 12928 次插入 和 1653 次删除

查看文件

@@ -3,9 +3,9 @@
* 严格遵循 uts 强类型规范与 AGENTS.md 约束
*/
import { BentoBlockPublic } from '../../common/types.uts';
import { fetchPortalCard } from '../../common/api.uts';
import { getCurrentLocale, getOmniText } from '../../common/locale.uts';
import { BentoBlockPublic, CardPortalDetail, RadarTrack } from '../../common/types.uts';
import { fetchPortalCard, recordRadarTrack } from '../../common/api.uts';
import { getCurrentLocale, getOmniText, OmniLocale } from '../../common/locale.uts';
export type ArticleDetailPageOptions = {
cardId?: string;
@@ -41,11 +41,21 @@ export type ArticleDetailState = {
empty: boolean;
errorMessage: string;
openGraph: ArticleOpenGraph;
authorName: string;
authorTitle: string;
authorCompany: string;
authorAvatar: string;
readTimeMinutes: number;
summaryText: string;
scrollDepth: number;
enterTime: number;
visitorId: string;
};
const SHARE_CTA_LABEL = '复制链接';
const BACK_LABEL = '返回';
const OG_DESC_MAX = 160;
const VISITOR_STORAGE_KEY = 'omni_visitor_id';
/**
* 创建文章详情初始状态
@@ -68,6 +78,15 @@ export function createArticleDetailState(): ArticleDetailState {
description: '',
image: '',
},
authorName: '',
authorTitle: '',
authorCompany: '',
authorAvatar: '',
readTimeMinutes: 1,
summaryText: '',
scrollDepth: 0,
enterTime: Date.now(),
visitorId: '',
};
}
@@ -87,6 +106,13 @@ export function applyEmptyArticle(state: ArticleDetailState): void {
description: '',
image: '',
};
state.authorName = '';
state.authorTitle = '';
state.authorCompany = '';
state.authorAvatar = '';
state.readTimeMinutes = 1;
state.summaryText = '';
state.scrollDepth = 0;
}
/**
@@ -241,7 +267,230 @@ export function getArticleEmptyMessage(): string {
return getOmniText(getCurrentLocale(), 'common.empty');
}
function applyArticle(state: ArticleDetailState, article: BentoBlockPublic): void {
export type ArticleDetailTextKey =
| 'kicker'
| 'shareCta'
| 'back'
| 'empty'
| 'emptyHint'
| 'summary'
| 'readTime'
| 'minRead'
| 'author'
| 'viewPortal';
/**
* 文章详情展示文案。严格遵循 AGENTS.md 多语言自然表达规范。
*/
export function resolveArticleDetailText(
key: ArticleDetailTextKey,
customLocale?: OmniLocale
): string {
const locale = customLocale != null ? customLocale : getCurrentLocale();
if (key === 'empty') {
return getOmniText(locale, 'common.empty');
}
if (locale === 'zh-CN') {
if (key === 'kicker') {
return '深度洞见';
}
if (key === 'summary') {
return '核心导读';
}
if (key === 'readTime') {
return '预计阅读';
}
if (key === 'minRead') {
return '分钟';
}
if (key === 'author') {
return '专栏作者';
}
if (key === 'viewPortal') {
return '查看微官网';
}
if (key === 'shareCta') {
return '复制分享链接';
}
if (key === 'back') {
return '返回';
}
return '返回上一页继续浏览';
}
if (locale === 'ar-SA') {
if (key === 'kicker') {
return 'رؤى متعمقة';
}
if (key === 'summary') {
return 'أبرز النقاط';
}
if (key === 'readTime') {
return 'وقت القراءة';
}
if (key === 'minRead') {
return 'دقائق';
}
if (key === 'author') {
return 'كاتب المقال';
}
if (key === 'viewPortal') {
return 'عرض الملف التعريفي';
}
if (key === 'shareCta') {
return 'نسخ رابط المشاركة';
}
if (key === 'back') {
return 'رجوع';
}
return 'ارجع للصفحة السابقة للمتابعة';
}
if (locale === 'es-ES') {
if (key === 'kicker') {
return 'Perspectivas';
}
if (key === 'summary') {
return 'Puntos clave';
}
if (key === 'readTime') {
return 'Tiempo de lectura';
}
if (key === 'minRead') {
return 'min';
}
if (key === 'author') {
return 'Autor';
}
if (key === 'viewPortal') {
return 'Ver perfil';
}
if (key === 'shareCta') {
return 'Copiar enlace para compartir';
}
if (key === 'back') {
return 'Volver';
}
return 'Vuelve para seguir leyendo';
}
if (locale === 'de-DE') {
if (key === 'kicker') {
return 'Brancheneinblick';
}
if (key === 'summary') {
return 'Kernaussagen';
}
if (key === 'readTime') {
return 'Lesezeit';
}
if (key === 'minRead') {
return 'Min.';
}
if (key === 'author') {
return 'Autor';
}
if (key === 'viewPortal') {
return 'Profil ansehen';
}
if (key === 'shareCta') {
return 'Freigabelink kopieren';
}
if (key === 'back') {
return 'Zurück';
}
return 'Gehen Sie zurück, um weiterzulesen';
}
if (locale === 'fr-FR') {
if (key === 'kicker') {
return 'Éclairage d’expert';
}
if (key === 'summary') {
return 'Points clés';
}
if (key === 'readTime') {
return 'Temps de lecture';
}
if (key === 'minRead') {
return 'min';
}
if (key === 'author') {
return 'Auteur';
}
if (key === 'viewPortal') {
return 'Voir le profil';
}
if (key === 'shareCta') {
return 'Copier le lien de partage';
}
if (key === 'back') {
return 'Retour';
}
return 'Revenez en arrière pour continuer';
}
if (locale === 'ja-JP') {
if (key === 'kicker') {
return 'インサイト';
}
if (key === 'summary') {
return '要約';
}
if (key === 'readTime') {
return '読了目安';
}
if (key === 'minRead') {
return '分';
}
if (key === 'author') {
return '執筆者';
}
if (key === 'viewPortal') {
return 'プロフィールを見る';
}
if (key === 'shareCta') {
return '共有リンクをコピー';
}
if (key === 'back') {
return '戻る';
}
return '前のページに戻って続きを見る';
}
if (key === 'kicker') {
return 'Thought Leadership';
}
if (key === 'summary') {
return 'Key Takeaways';
}
if (key === 'readTime') {
return 'Read time';
}
if (key === 'minRead') {
return 'min';
}
if (key === 'author') {
return 'Author';
}
if (key === 'viewPortal') {
return 'View Profile';
}
if (key === 'shareCta') {
return 'Copy share link';
}
if (key === 'back') {
return 'Back';
}
return 'Go back to keep reading';
}
function applyArticle(
state: ArticleDetailState,
article: BentoBlockPublic,
card?: CardPortalDetail | null
): void {
state.article = article;
state.title = article.title != null ? article.title : '';
state.content = article.content != null ? article.content : '';
@@ -250,10 +499,21 @@ function applyArticle(state: ArticleDetailState, article: BentoBlockPublic): voi
state.isHtmlContent = looksLikeHtml(state.content);
state.empty = false;
state.openGraph = buildArticleOpenGraph(article);
const cleanText = stripHtmlToText(state.content);
state.readTimeMinutes = Math.max(1, Math.ceil(cleanText.length / 350));
state.summaryText = state.openGraph.description;
if (card != null) {
state.authorName = card.name != null ? String(card.name) : '';
state.authorTitle = card.title != null ? String(card.title) : '';
state.authorCompany = card.company != null ? String(card.company) : '';
state.authorAvatar = card.avatarUrl != null ? String(card.avatarUrl) : '';
}
}
/**
* fetchPortalCard 后从 bentoBlocks 选出 article
* fetchPortalCard 后从 bentoBlocks 选出 article 并绑定作者与元信息
*/
export async function loadArticleDetail(
state: ArticleDetailState
@@ -265,6 +525,7 @@ export async function loadArticleDetail(
state.loading = true;
state.errorMessage = '';
state.enterTime = Date.now();
try {
const card = await fetchPortalCard(state.cardId);
@@ -277,7 +538,7 @@ export async function loadArticleDetail(
return null;
}
applyArticle(state, article);
applyArticle(state, article, card);
return article;
} catch (err) {
state.loading = false;
@@ -291,6 +552,95 @@ export async function loadArticleDetail(
}
}
/**
* 获取或初始化访客唯一识别码 (持久化在本地 Storage)
*/
export function getOrCreateVisitorId(): string {
let visitorId = '';
try {
visitorId = uni.getStorageSync(VISITOR_STORAGE_KEY) as string;
} catch (_e) {
visitorId = '';
}
if (!visitorId || visitorId.trim() === '') {
const randomPart = Math.random().toString(36).substring(2, 10);
visitorId = `vis_${Date.now()}_${randomPart}`;
try {
uni.setStorageSync(VISITOR_STORAGE_KEY, visitorId);
} catch (_e) {}
}
return visitorId;
}
/**
* 记录并更新滑屏深度 (0 - 100%)
*/
export function updateArticleScrollDepth(
state: ArticleDetailState,
scrollTop: number,
scrollHeight: number,
windowHeight: number
): number {
if (scrollHeight <= 0) {
return state.scrollDepth;
}
const maxScroll = Math.max(1, scrollHeight - windowHeight);
const currentRatio = Math.min(1, Math.max(0, scrollTop / maxScroll));
const depth = Math.round(currentRatio * 100);
if (depth > state.scrollDepth) {
state.scrollDepth = depth;
}
return state.scrollDepth;
}
/**
* 上报文章阅读停留时长与滑屏深度至访客雷达 CRM
*/
export async function reportArticleStay(
state: ArticleDetailState,
scrollDepth?: number
): Promise<RadarTrack | null> {
if (state.cardId === '' || state.blockId === '') {
return null;
}
const currentDepth = scrollDepth != null ? scrollDepth : state.scrollDepth;
const enter = state.enterTime > 0 ? state.enterTime : Date.now();
const stayDurationMs = Math.max(0, Date.now() - enter);
const visitorId = state.visitorId !== '' ? state.visitorId : getOrCreateVisitorId();
try {
const track = await recordRadarTrack({
cardId: state.cardId,
visitorId,
touchType: 'link',
stayDurationMs,
scrollDepth: currentDepth,
viewedBlocks: [state.blockId],
});
return track;
} catch (_e) {
return null;
}
}
/**
* 导航至专栏作者的名片主微官网
*/
export function navToAuthorPortal(state: ArticleDetailState): void {
if (state.cardId === '') {
return;
}
uni.navigateTo({
url: `/pages/portal/index?id=${state.cardId}`,
fail: () => {
uni.reLaunch({
url: `/pages/portal/index?id=${state.cardId}`,
});
},
});
}
/**
* 主 CTA:复制 linkUrl 或当前页 URL
*/