feat: 新增多语言文案与组件国际化适配
本次提交完成了大量多语言相关的新增与优化工作: 1. 新增充值、案例、会员资产、订单等页面的中文/英文翻译文案 2. 新增企业微信客服、时间选择、支付弹窗等组件的多语言包 3. 优化工具函数与自定义页面的多语言适配,替换硬编码提示文案 4. 新增会员等级规则、积分商品、退款管理等页面的国际化支持 5. 修复企业微信JS-SDK的错误提示文案硬编码问题
This commit is contained in:
@@ -307,15 +307,64 @@ function main() {
|
||||
// 中文正则(基本汉字区)
|
||||
const CN_RE = /[\u4e00-\u9fa5]+/g;
|
||||
|
||||
// 判断一行是否是注释行(粗略)
|
||||
function isCommentLine(line) {
|
||||
const t = line.trim();
|
||||
if (t.startsWith('//')) return true;
|
||||
if (t.startsWith('/*')) return true;
|
||||
if (t.startsWith('*')) return true;
|
||||
if (t.startsWith('<!--')) return true;
|
||||
if (t.startsWith('* ')) return true;
|
||||
return false;
|
||||
// 去掉行内注释(// 和 /* */ 块注释单行)
|
||||
function stripInlineComment(line, inBlockComment) {
|
||||
let result = line;
|
||||
let inString = false;
|
||||
let stringChar = '';
|
||||
let i = 0;
|
||||
|
||||
while (i < result.length) {
|
||||
const ch = result[i];
|
||||
const next = result[i + 1];
|
||||
|
||||
if (inBlockComment) {
|
||||
// 块注释中,找 */
|
||||
if (ch === '*' && next === '/') {
|
||||
inBlockComment = false;
|
||||
result = result.substring(0, i) + ' ' + result.substring(i + 2);
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
// 替换为空格保持位置
|
||||
result = result.substring(0, i) + ' ' + result.substring(i + 1);
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inString) {
|
||||
if (ch === '\\') { i += 2; continue; } // 转义
|
||||
if (ch === stringChar) { inString = false; }
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 字符串开始
|
||||
if (ch === "'" || ch === '"' || ch === '`') {
|
||||
inString = true;
|
||||
stringChar = ch;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 行注释
|
||||
if (ch === '/' && next === '/') {
|
||||
result = result.substring(0, i);
|
||||
break;
|
||||
}
|
||||
|
||||
// 块注释开始
|
||||
if (ch === '/' && next === '*') {
|
||||
inBlockComment = true;
|
||||
result = result.substring(0, i) + ' ' + result.substring(i + 2);
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return { text: result, inBlockComment };
|
||||
}
|
||||
|
||||
// 判断一行是否是 $lang 调用(已经国际化)
|
||||
@@ -332,10 +381,38 @@ function main() {
|
||||
const content = fs.readFileSync(fullPath, 'utf-8');
|
||||
const lines = content.split('\n');
|
||||
let fileHits = 0;
|
||||
let inBlockComment = false;
|
||||
let inHtmlComment = false;
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
if (isCommentLine(line)) continue;
|
||||
let line = lines[i];
|
||||
|
||||
// HTML 注释块处理 (<!-- -->)
|
||||
if (inHtmlComment) {
|
||||
const endIdx = line.indexOf('-->');
|
||||
if (endIdx >= 0) {
|
||||
line = line.substring(endIdx + 3);
|
||||
inHtmlComment = false;
|
||||
} else {
|
||||
continue; // 整行在 HTML 注释中
|
||||
}
|
||||
}
|
||||
const htmlStart = line.indexOf('<!--');
|
||||
if (htmlStart >= 0) {
|
||||
const htmlEnd = line.indexOf('-->', htmlStart);
|
||||
if (htmlEnd >= 0) {
|
||||
line = line.substring(0, htmlStart) + line.substring(htmlEnd + 3);
|
||||
} else {
|
||||
line = line.substring(0, htmlStart);
|
||||
inHtmlComment = true;
|
||||
}
|
||||
}
|
||||
|
||||
// JS/CSS 块注释 + 行注释处理
|
||||
const stripped = stripInlineComment(line, inBlockComment);
|
||||
inBlockComment = stripped.inBlockComment;
|
||||
line = stripped.text;
|
||||
|
||||
if (isLangCall(line)) continue;
|
||||
|
||||
const matches = line.match(CN_RE);
|
||||
|
||||
Reference in New Issue
Block a user