Skip to content

Commit 6b43e84

Browse files
committed
feat: huoshan web
1 parent 6f45503 commit 6b43e84

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ The default service is Google Translate. Currently, we support:
106106
| NLLB | No **[Require config]** | [nllb-api](https://github.com/winstxnhdw/nllb-api?tab=readme-ov-file#self-hosting) or [NLLB Serve](https://github.com/thammegowda/nllb-serve?tab=readme-ov-file#setup) |
107107
| Pot | No **[Require config]** | [Pot](https://github.com/pot-app/pot-desktop) _Translate results show in Pot_ |
108108
| Huoshan | Yes | [50+](https://www.volcengine.com/docs/4640/127681) |
109+
| Volcengine Web | No **[Free]** | [en, zh, and more (auto-detect, web version)](https://translate.volcengine.com/) |
109110
| Youdao Zhiyun | Yes | [100+](https://ai.youdao.com/DOCSIRMA/html/trans/api/wbfy/index.html) |
110111
| Youdao LLM | Yes | [LLM-based](https://ai.youdao.com/DOCSIRMA/html/trans/api/dmxfy/index.html)(en-zh) |
111112
| Niu Trans | Yes | [400+](https://niutrans.com/documents/contents/trans_text#accessMode) |

addon/locale/en-US/addon.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
service-huoshanweb=Volcengine Web
12
service-tencenttransmart=Tencent Transmart
23
service-huoshan=Huoshan
34
service-googleapi=Google(API)

addon/locale/it-IT/addon.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
service-huoshanweb=Volcengine Web
12
service-tencenttransmart=Tencent Transmart
23
service-huoshan=Huoshan
34
service-googleapi=Google(API)

addon/locale/zh-CN/addon.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
service-huoshanweb=火山网页翻译
12
service-tencenttransmart=腾讯TranSmart
23
service-huoshan=火山翻译
34
service-googleapi=Google(API)

src/modules/services/huoshanweb.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { TranslateService } from "./base";
2+
3+
// https://github.com/TechDecryptor/pot-app-translate-plugin-volcengine
4+
export const HuoshanWeb: TranslateService = {
5+
id: "huoshanweb",
6+
name: "Huoshan Web",
7+
type: "sentence" as const,
8+
translate: async function (data) {
9+
const { raw: text } = data;
10+
const from = (data.langfrom || "").split("-")[0];
11+
const to = (data.langto || "").split("-")[0];
12+
const URL = "https://translate.volcengine.com/crx/translate/v1";
13+
const body = {
14+
source_language: from,
15+
target_language: to,
16+
text,
17+
};
18+
const headers = {
19+
"content-type": "application/json",
20+
};
21+
const xhr = await Zotero.HTTP.request("POST", URL, {
22+
headers,
23+
body: JSON.stringify(body),
24+
responseType: "json",
25+
});
26+
if (xhr.status !== 200) {
27+
throw `Request error: ${xhr.status}`;
28+
}
29+
const result = xhr.response;
30+
const { translation } = result;
31+
if (translation) {
32+
data.result = translation;
33+
} else {
34+
throw JSON.stringify(result);
35+
}
36+
},
37+
};

src/modules/services/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { Google, GoogleAPI } from "./google";
2727
import { Haici } from "./haici";
2828
import { HaiciDict } from "./haicidict";
2929
import { Huoshan } from "./huoshan";
30+
import { HuoshanWeb } from "./huoshanweb";
3031
import { LibreTranslate } from "./libretranslate";
3132
import { Microsoft } from "./microsoft";
3233
import { Mtranserver } from "./mtranserver";
@@ -72,6 +73,7 @@ const register: TranslateService[] = [
7273
Haici,
7374
HaiciDict,
7475
Huoshan,
76+
HuoshanWeb,
7577
LibreTranslate,
7678
Microsoft,
7779
Mtranserver,

typings/i10n.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export type FluentMessageId =
154154
| 'service-haici'
155155
| 'service-haicidict'
156156
| 'service-huoshan'
157+
| 'service-huoshanweb'
157158
| 'service-libretranslate'
158159
| 'service-libretranslate-dialog-endPoint'
159160
| 'service-manageKeys-close'

0 commit comments

Comments
 (0)