Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
fix: 修改一些小问题,减少日志占用
Browse files Browse the repository at this point in the history
  • Loading branch information
silver-ymz committed Oct 9, 2022
1 parent 292b0e9 commit cc99d5e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const RollupConfig = {
targets: [
{ src: './src/info.json', dest: `dist/${pkg}/` },
{ src: './src/libs', dest: `dist/${pkg}/` },
{ src: './src/icon.png', dest: `dist/${pkg}/` }
{ src: './src/icon.png', dest: `dist/${pkg}/` },
],
}),
json({ namedExports: false }),
Expand Down
2 changes: 1 addition & 1 deletion src/appcast.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"version": "0.2.0",
"desc": "https://github.com/silver-ymz/bob-plugin-microsoft-translate/blob/master/CHANGELOG.md",
"sha256": "d2081a3ed1c40edb28dbda3215cbe6c9af4aa5edc6d7c8c2e2e4bf9c391e396a",
"sha256": "5314611c7f7cb7a79b83ba07b31591eeaeabebb1673677de1685f9de74949ca9",
"url": "https://github.com/silver-ymz/bob-plugin-microsoft-translate/releases/download/v0.2.0/bob-plugin-microsoft-translate-v0.2.0.bobplugin",
"minBobVersion": "0.5.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{
"identifier": "key",
"type": "text",
"title": "Secret Key"
"title": "密钥"
},
{
"identifier": "location",
Expand Down
14 changes: 8 additions & 6 deletions src/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ async function _translate(text: string, options: QueryOption): Promise<Bob.Trans
resultCache.clear();
}

const result: Bob.TranslateResult = { from, to, toParagraphs: [] };

const endpoint = Bob.api.getOption('endpoint');
let endpoint = Bob.api.getOption('endpoint');
if (!endpoint.startsWith('https://'))
endpoint = 'https://' + endpoint;
const path = '/translate?api-version=3.0';
const fromLanguageParameter = '&from=' + standardToNoStandard(from);
const targetLanguageParameter = '&to=' + standardToNoStandard(to);
const constructedUrl = endpoint + path + fromLanguageParameter + targetLanguageParameter;
const postUrl = endpoint + path + fromLanguageParameter + targetLanguageParameter;
const key = Bob.api.getOption('key');
const location = Bob.api.getOption('location');
const headers = {
Expand All @@ -41,7 +41,7 @@ async function _translate(text: string, options: QueryOption): Promise<Bob.Trans
};
const [err, res] = await Bob.util.asyncTo<Bob.HttpResponse>(
Bob.api.$http.post({
url: constructedUrl,
url: postUrl,
header: headers,
body: [{ text: text }],
}),
Expand All @@ -50,10 +50,12 @@ async function _translate(text: string, options: QueryOption): Promise<Bob.Trans
const resData = res?.data;
Bob.api.$log.info(JSON.stringify(res));

const result: Bob.TranslateResult = { from, to, toParagraphs: [] };

try {
// 在此处实现翻译的具体处理逻辑
result.toParagraphs = [resData[0].translations[0].text];
// result.toDict = { parts: [], phonetics: [] };

} catch (error) {
throw Bob.util.error('api', '数据解析错误', error);
}
Expand Down

0 comments on commit cc99d5e

Please sign in to comment.