From 5d91dace5a29482ae8f1f48adada8fe232b2f4c1 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Thu, 8 Jun 2023 12:13:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9i8n=20=E5=A2=9E=E5=8A=A0=20t(ele)=20t(?= =?UTF-8?q?ele.label)=E7=9A=84=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/babel-plugin/oakI18n.js | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/config/babel-plugin/oakI18n.js b/config/babel-plugin/oakI18n.js index 980cf71..05a31ac 100644 --- a/config/babel-plugin/oakI18n.js +++ b/config/babel-plugin/oakI18n.js @@ -43,11 +43,49 @@ module.exports = (babel) => { node2.value && node2.value.indexOf(':') === -1 ) { + // t('d') arguments.splice( index, 1, t.stringLiteral(ns + ':' + node2.value) ); + } else if ( + index === 0 && + t.isIdentifier(node2) && + node2.name && + node2.name.indexOf(':') === -1 + ) { + // t(ele) + arguments.splice( + index, + 1, + t.binaryExpression( + '+', + t.stringLiteral(ns + ':'), + t.identifier(node2.name) + ) + ); + } else if ( + index === 0 && + t.isMemberExpression(node2) && + node2.object.name && + node2.object.name.indexOf(':') === -1 + ) { + // t(ele.label) + arguments.splice( + index, + 1, + t.binaryExpression( + '+', + t.stringLiteral(ns + ':'), + t.memberExpression( + t.identifier( + node2.object.name + ), + t.identifier(node2.property.name) + ) + ) + ); } else if ( index === 0 && t.isTemplateLiteral(node2) && @@ -60,6 +98,7 @@ module.exports = (babel) => { node3.value.raw.indexOf(':') !== -1 ) ) { + // t(`ele`) node2.quasis.splice( 0, 1,