You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2021/02/07 14:40:13 UTC

[echarts-bot] branch master updated: fix: tweak English language check logic.

This is an automated email from the ASF dual-hosted git repository.

wangzx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/echarts-bot.git


The following commit(s) were added to refs/heads/master by this push:
     new 2841d08  fix: tweak English language check logic.
2841d08 is described below

commit 2841d0858c73c97e281d208bf30c7223f69eea7c
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Sun Feb 7 22:39:15 2021 +0800

    fix: tweak English language check logic.
---
 src/translator.js       |  3 ++-
 src/util.js             |  3 ++-
 test/translator.test.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/translator.js b/src/translator.js
index baf2bbb..888c4e9 100644
--- a/src/translator.js
+++ b/src/translator.js
@@ -43,7 +43,8 @@ function detectLanguage(text, detectAll) {
 
 function detectEnglish(text) {
   const lang = detectLanguage(text, true);
-  return lang[0][0] === 'eng' && (!lang[1] || lang[1][1] < 0.9);
+  return lang[0][0] === 'eng'
+      && (!lang[1] || (lang[1][0] === 'sco' && lang[1][1] > 0.9) || lang[1][1] < 0.9);
 }
 
 module.exports = {
diff --git a/src/util.js b/src/util.js
index 0dea8fd..5924bc7 100644
--- a/src/util.js
+++ b/src/util.js
@@ -1,7 +1,8 @@
 function removeCodeAndComment(body) {
 	return body
 		.replace(/<!--[\w\W\r\n]*?-->/gmi, '')
-		.replace(/`{3}(.|\n)*`{3}/gmi, '');
+		.replace(/`{3}(.|\n)*`{3}/gmi, '')
+        .replace(/#.*\n/g, '');
 }
 
 function replaceAll(str, search, replacement) {
diff --git a/test/translator.test.js b/test/translator.test.js
new file mode 100644
index 0000000..496841e
--- /dev/null
+++ b/test/translator.test.js
@@ -0,0 +1,49 @@
+const { removeCodeAndComment } = require('../src/util')
+const { detectEnglish } = require('../src/translator')
+
+const str = `
+### What problem does this feature solve?
+I wish to show chemical structure / latex formula or some other complex content in a tooltip canvas.
+I have the function (based on zrender) to draw these objects and I wish there is an API hooker to help me.
+An extra AJAX request may be required to fetch the more data during the render.
+
+### What does the proposed API look like?
+\`\`\`
+tooltip: {
+    size: [150, 50], // The tooltip size prepared for render
+    onRender: function (
+        data,       // The data of the selected point
+        render,     // The echart/zrender object to draw on
+        boundRect   // The bound rectangle to draw in
+    ) {
+        axios.get("/some.api?id="   data["id"]).then(function (response) {
+            // Do some drawing code here.
+        })
+    }
+}
+\`\`\`
+
+<!-- This issue is generated by echarts-issue-helper. DO NOT REMOVE -->
+<!-- This issue is in English. DO NOT REMOVE -->`;
+
+const str2 = `
+### What problem does this feature solve?
+
+比如 series-line.itemStyle. color 可以是一个函数,于是就可以动态修改每一个折线点的颜色。能不能让series-line.lineStyle. color 也可以是一个函数,这样就能动态修改每一小段折线的颜色,或者将它隐藏起来。
+
+### What does the proposed API look like?
+series-line.lineStyle. color 可以是一个函数,能动态修改每一小段折线的颜色,或者将它隐藏起来。
+
+<!-- This issue is generated by echarts-issue-helper. DO NOT REMOVE -->`;
+
+describe('translator and language test', () => {
+    it('The language should be English', () => {
+        const c = removeCodeAndComment(str);
+        expect(detectEnglish(c)).toEqual(true);
+    });
+
+    it('The language should be not English', () => {
+        const c = removeCodeAndComment(str2);
+        expect(detectEnglish(c)).toEqual(false);
+    });
+});


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org