From 1ae7b7f1773f9189e97c75cc102092302880b1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=B3=BD=E6=B1=9F?= Date: Thu, 16 May 2024 22:29:36 +0800 Subject: [PATCH] fix(bin): fix extra text error from t.t('xxx') 'xxx' is key but not the text --- src/bin/extra-text.ts | 2 +- test/bin/extra-text.test.ts | 1 + test/i18n/text.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bin/extra-text.ts b/src/bin/extra-text.ts index 2dc3bf0..887b0c9 100644 --- a/src/bin/extra-text.ts +++ b/src/bin/extra-text.ts @@ -38,7 +38,7 @@ export function extraTextFromT( error: string[], ) { const regexp = new RegExp( - /\WfuncName\(\n*[ ]*((['"`])(.+?)\2)(,|\))/.source.replace( + /[^.A-z]funcName\(\n*[ ]*((['"`])(.+?)\2)(,|\))/.source.replace( 'funcName', funcName, ), diff --git a/test/bin/extra-text.test.ts b/test/bin/extra-text.test.ts index ab017d6..ee19bc2 100644 --- a/test/bin/extra-text.test.ts +++ b/test/bin/extra-text.test.ts @@ -16,6 +16,7 @@ describe('验证 t 翻译文本提取功能', () => { '我叫{0},今年{1}岁,来自{2},是一名{3}', 'a', 'b', + '文案', ] const errrorTexts = [ diff --git a/test/i18n/text.ts b/test/i18n/text.ts index 0940716..3b5edf9 100644 --- a/test/i18n/text.ts +++ b/test/i18n/text.ts @@ -23,3 +23,4 @@ t('普通文本') t('普通文本{0}', foo) t('我叫{0},今年{1}岁,来自{2},是一名{3}', '王尼玛', '22', '火星', '码农') t('a', t('b')) +t.t('自定义key', t.t('自定义key2', t('文案')))