282ad7be9f
后端仍有出口把底层异常原文写进 error_message / fileError / 匹配原因 / 响应 message,逐条翻译
跟不上新增;用户 2026-10-09 要求整个项目的提示语都用中文,所以把规矩做进界面出口。
规则:原文含中文照原样透出;整条无中文换成中文兜底句;**含中文但冒号后是纯英文尾巴的剥掉尾巴**
("转换结果打包失败: No space left on device" 只留主干)。被隐去的原文进 console 供核对日志。
闸口:用户端 http.ts 的 extractErrorMessage 五条返回路径与 unwrapJavaResponse、后台 envelope 的
textOf/errorTextOf、13 处任务卡 `错误:${item.error}`、2 处 fileError 兜底句、发布页文件错误与
匹配原因函数、dispatch-guard 的解析失败原因清单、22 处 ElMessage.error(result.error) 型展示、
后台看板与数字人详情页两处模板。
尺子:frontend-vue/tests/user-notice-chinese-only-guard.test.ts、admin-frontend-vue/tests/user-notice-chinese-only.test.ts
(分母硬钉+内存造违例自证+摘壳写法仍计入分母);source-pin 台账只登记本轮新增那一个文件,
别人的在飞格子没重算。node --test 用户端 782/782、后台 1782/1782,两棵树 vue-tsc 均 rc=0。
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
/**
|
||
* 后台提示语把关(2026-10-09):只把中文给用户看。
|
||
*
|
||
* Java 侧仍有出口把底层异常原文写进 message/errorMessage,后台同学看到
|
||
* `Invalid export date range` 这类句子既看不懂也没法转述给用户。这里统一换成中文兜底句,
|
||
* 原文进 console 供对着日志核对。
|
||
*/
|
||
|
||
const CJK = /[\u3400-\u4dbf\u4e00-\u9fff]/
|
||
|
||
export const NOTICE_FALLBACK = '操作未能完成,请稍后重试'
|
||
|
||
export function userNotice(text?: string | null, fallback: string = NOTICE_FALLBACK): string {
|
||
const raw = typeof text === 'string' ? text.trim() : ''
|
||
if (!raw) {
|
||
return fallback
|
||
}
|
||
if (!CJK.test(raw)) {
|
||
console.warn('[user-notice] 提示语原文不是中文,已换成中文兜底句,原文:', raw)
|
||
return fallback
|
||
}
|
||
// 中文主干 + 英文尾巴(后端把底层异常原文拼在冒号后):留主干,尾巴只进 console
|
||
const at = Math.max(raw.lastIndexOf(':'), raw.lastIndexOf(':'))
|
||
if (at > 0 && !CJK.test(raw.slice(at + 1))) {
|
||
const head = raw.slice(0, at).trim()
|
||
if (CJK.test(head)) {
|
||
console.warn('[user-notice] 提示语尾巴是英文,已隐去,原文:', raw)
|
||
return head
|
||
}
|
||
}
|
||
return raw
|
||
}
|