diff --git a/README.md b/README.md index a6788ce..b3295b3 100644 --- a/README.md +++ b/README.md @@ -141,9 +141,11 @@ The secret format is `accessKeyId#accessKeySecret` **Aliyun Translate** Apply [here](https://www.aliyun.com/product/ai/base_alimt). -The secret format is `accessKeyId#accessKeySecret`. +The secret format is `accessKeyId#accessKeySecret#endpoint(optional)`. -> [Chinere Document](https://help.aliyun.com/document_detail/158269.html) +> The endpoint is the region of the service, default `https://mt.aliyuncs.com`. For `cn-hangzhou`, the endpoint is `mt.cn-hangzhou.aliyuncs.com`. See also [here](https://help.aliyun.com/zh/machine-translation/developer-reference/api-alimt-2018-10-12-endpoint?spm=a2c4g.11186623.help-menu-30396.d_4_1_0.6c702fa7WlNkX1). + +> [Chinese Document](https://help.aliyun.com/document_detail/158269.html) **Baidu Translate** Apply [here](https://fanyi-api.baidu.com/product/11). diff --git a/src/modules/services/aliyun.ts b/src/modules/services/aliyun.ts index 4bbd121..66e7772 100644 --- a/src/modules/services/aliyun.ts +++ b/src/modules/services/aliyun.ts @@ -5,6 +5,7 @@ export default async function (data) { const params = data.secret.split("#"); const accessKeyId = params[0]; const accessKeySecret = params[1]; + const endpoint = params[2] || "https://mt.aliyuncs.com/"; function languageCode(str: string) { str = str.toLowerCase(); @@ -35,7 +36,7 @@ export default async function (data) { await hmacSha1Digest(stringToSign, `${accessKeySecret}&`), ); - const xhr = await Zotero.HTTP.request("POST", "https://mt.aliyuncs.com/", { + const xhr = await Zotero.HTTP.request("POST", endpoint, { headers: { "Content-Type": "application/x-www-form-urlencoded", },