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 d8d109b feat: enable new bing translator MET mode
d8d109b is described below
commit d8d109b2512ce215c6bf8da5a2528cabae4833f5
Author: plainheart <[email protected]>
AuthorDate: Thu Mar 7 09:29:27 2024 +0800
feat: enable new bing translator MET mode
---
src/translator.js | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/translator.js b/src/translator.js
index 67384db..62eafc8 100644
--- a/src/translator.js
+++ b/src/translator.js
@@ -1,5 +1,5 @@
const googleTranslate = require('@plainheart/google-translate-api');
-const { translate: bingTranslate } = require('bing-translate-api');
+const { translate: bingTranslate, MET: { translate: bingTranslateMET } } =
require('bing-translate-api');
const franc = require('franc-min');
const logger = require('./logger');
@@ -41,6 +41,21 @@ async function translateByBing(rawContent) {
}
}
+async function translateByBingMET(rawContent) {
+ try {
+ const [res] = await bingTranslateMET(rawContent);
+ return {
+ translated: res.translations[0].text,
+ lang: res.detectedLanguage.language,
+ translator: 'bingMET'
+ };
+ }
+ catch (e) {
+ logger.error('failed to translate by bing MET');
+ logger.error(e);
+ }
+}
+
/**
* To translate the raw sentence to English
* @param {string} rawContent sentence to be translated
@@ -50,7 +65,7 @@ async function translate(rawContent) {
if (!rawContent || !(rawContent = rawContent.trim())) {
return;
}
- const translators = [translateByGoogle, translateByBing];
+ const translators = [translateByGoogle, translateByBing,
translateByBingMET];
const randomIdx = ~~(Math.random() * translators.length);
let res = await translators[randomIdx](rawContent);
if (!res) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]