Update Translator.plugin.js
This commit is contained in:
parent
b8ca969beb
commit
a04cb64d85
|
@ -315,7 +315,7 @@ module.exports = (_ => {
|
|||
},
|
||||
papago: {
|
||||
name: "Papago",
|
||||
auto: false,
|
||||
auto: true,
|
||||
funcName: "papagoTranslate",
|
||||
languages: ["en","es","fr","id","ja","ko","th","vi","zh-CN","zh-TW"],
|
||||
key: "xxxxxxxxxxxxxxxxxxxx xxxxxxxxxx"
|
||||
|
@ -1112,10 +1112,11 @@ module.exports = (_ => {
|
|||
|
||||
papagoTranslate (data, callback) {
|
||||
const credentials = (authKeys.papago && authKeys.papago.key || "kUNGxtAmTJQFbaFehdjk zC70k3VhpM").split(" ");
|
||||
const doTranslate = langCode => {
|
||||
BDFDB.LibraryRequires.request("https://openapi.naver.com/v1/papago/n2mt", {
|
||||
method: "post",
|
||||
form: {
|
||||
source: data.input.id,
|
||||
source: langCode,
|
||||
target: data.output.id,
|
||||
text: data.text
|
||||
},
|
||||
|
@ -1146,6 +1147,33 @@ module.exports = (_ => {
|
|||
callback("");
|
||||
}
|
||||
});
|
||||
};
|
||||
if (data.input.auto) {
|
||||
BDFDB.LibraryRequires.request("https://openapi.naver.com/v1/papago/detectLangs", {
|
||||
method: "post",
|
||||
form: {
|
||||
query: data.text,
|
||||
},
|
||||
headers: {
|
||||
"X-Naver-Client-Id": credentials[0],
|
||||
"X-Naver-Client-Secret": credentials[1],
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
}, (error, response, body) => {
|
||||
let langCode = "en";
|
||||
if (!error && body && response.statusCode == 200) {
|
||||
try {
|
||||
langCode = JSON.parse(body)["langCode"];
|
||||
} catch (err) {
|
||||
langCode = "en";
|
||||
}
|
||||
}
|
||||
data.input.name = languages[langCode].name;
|
||||
data.input.ownlang = languages[langCode].ownlang;
|
||||
doTranslate(langCode);
|
||||
});
|
||||
}
|
||||
else doTranslate(data.input.id);
|
||||
}
|
||||
|
||||
baiduTranslate (data, callback) {
|
||||
|
|
Loading…
Reference in New Issue