From 17310257446832fea962b014393b0e2b902e2ea2 Mon Sep 17 00:00:00 2001 From: jingrow Date: Tue, 30 Dec 2025 03:58:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96vite=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/vite-plugin-translate.mjs | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/dashboard/vite-plugin-translate.mjs b/dashboard/vite-plugin-translate.mjs index 8b68328..a2ae5c0 100644 --- a/dashboard/vite-plugin-translate.mjs +++ b/dashboard/vite-plugin-translate.mjs @@ -180,8 +180,8 @@ function vitePluginTranslate(options = {}) { code = replaceCompiledFormat(code, translations); code = replaceAttributeBindings(code, translations); } else if (isScriptModule) { - // Vue 编译后的 script 模块 - 需要处理 this.$t()、$t() 以及编译后的函数调用(如 le()、t()) - // 先处理 this.$t() 和 $t() + // Vue 编译后的 script 模块 - 处理 this.$t() 和 $t() 调用 + // 注意:t() 函数调用已在原始 Vue SFC 文件中处理,编译后应该已经是翻译后的字符串 code = code.replace( /(?:this\.)?\$t\((['"])((?:\\.|(?!\1).)*)\1\)/g, (match, quote, key) => { @@ -193,23 +193,6 @@ function vitePluginTranslate(options = {}) { return match; } ); - // 再处理编译后的函数调用(如 le("key")、t("key")) - // 匹配函数名后跟括号和字符串参数 - code = code.replace( - /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\((['"])((?:\\.|(?!\2).)*)\2\)/g, - (match, funcName, quote, key) => { - // 只处理可能是翻译函数的调用(通常是单字母或短名称,如 t, le, i 等) - // 但排除明显的非翻译函数(如 console.log, JSON.parse 等) - if (funcName.length <= 3 && !['log', 'warn', 'error', 'parse', 'stringify', 'keys', 'values', 'entries'].includes(funcName)) { - const unescapedKey = unescapeString(key); - const translation = translations[unescapedKey]; - if (translation) { - return funcName + '(' + quote + escapeString(translation, quote) + quote + ')'; - } - } - return match; - } - ); } else { // 原始 Vue SFC 文件 code = processVueSFC(code, translations);