From 8c4d3b8ead41812bbe837dc5dfb8fa047cd2b548 Mon Sep 17 00:00:00 2001 From: chenxingchun <438044805@qq.com> Date: Fri, 25 Jun 2021 14:51:41 +0800 Subject: [PATCH] modify body to string --- dist/index.js | 13 ++++++------- src/main.js | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3b4c79f..0497e32 100644 --- a/dist/index.js +++ b/dist/index.js @@ -15561,7 +15561,7 @@ async function run() { const translateTitle = core.getInput('translate-title') || 'true'; const translateBody = core.getInput('translate-body') || 'true'; - if (translateTitle == 'true' && !checkIsEn(title)) { + if (translateTitle == 'true' && containsChinese(title)) { const { text: newTitle } = await translate(title, { to: 'en' }); core.info(`[translate] [title out: ${newTitle}]`); await octokit.issues.update({ @@ -15573,7 +15573,7 @@ async function run() { core.info(`[update title] [number: ${number}]`); } - if (translateBody == 'true' && !checkIsEn(body)) { + if (translateBody == 'true' && containsChinese(body)) { const { text: newBody } = await translate(body, { to: 'en' }); core.info(`[translate] [body out: ${newBody}]`); await octokit.issues.createComment({ @@ -15594,12 +15594,11 @@ async function run() { } } -function checkIsEn(body) { - var en = /^[a-zA-Z0-9_\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'<>~\·`\?:;|\s]*$/; - const bodyType = typeof body; +function containsChinese(body) { + var patt = /[\u4e00-\u9fa5]/; const bodyString = body.toString().trim(); - const result = en.test(bodyString); - core.info(`[CheckIsEn] [body type is ${bodyType}, ${body} is ${result}]`); + const result = patt.test(bodyString); + core.info(`[containsChinese] [${body} is ${result}]`); return result; } diff --git a/src/main.js b/src/main.js index c419990..e3a3718 100644 --- a/src/main.js +++ b/src/main.js @@ -31,7 +31,7 @@ async function run() { const translateTitle = core.getInput('translate-title') || 'true'; const translateBody = core.getInput('translate-body') || 'true'; - if (translateTitle == 'true' && !checkIsEn(title)) { + if (translateTitle == 'true' && containsChinese(title)) { const { text: newTitle } = await translate(title, { to: 'en' }); core.info(`[translate] [title out: ${newTitle}]`); await octokit.issues.update({ @@ -43,7 +43,7 @@ async function run() { core.info(`[update title] [number: ${number}]`); } - if (translateBody == 'true' && !checkIsEn(body)) { + if (translateBody == 'true' && containsChinese(body)) { const { text: newBody } = await translate(body, { to: 'en' }); core.info(`[translate] [body out: ${newBody}]`); await octokit.issues.createComment({ @@ -64,12 +64,11 @@ async function run() { } } -function checkIsEn(body) { - var en = /^[a-zA-Z0-9_\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'<>~\·`\?:;|\s]*$/; - const bodyType = typeof body; +function containsChinese(body) { + var patt = /[\u4e00-\u9fa5]/; const bodyString = body.toString().trim(); - const result = en.test(bodyString); - core.info(`[CheckIsEn] [body type is ${bodyType}, ${body} is ${result}]`); + const result = patt.test(bodyString); + core.info(`[containsChinese] [${body} is ${result}]`); return result; }