Skip to content

Commit b030f0f

Browse files
committed
fix: bing translate with standard tone
1 parent a5300c4 commit b030f0f

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 1.0.7
2+
3+
## Lib
4+
5+
- Fix Bing Translate with `Standard` tone
6+
7+
## Workspace
8+
9+
- Bump depends
10+
111
# 1.0.6
212

313
## Lib

src/providers/bing.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { ProviderError, TranslateError } from "@/errors";
2020
import { getUUID } from "@/utils/secure";
2121

2222
export default class BingTranslateProvider extends BaseProvider {
23-
apiUrlPlaceholder = "https://www.bing.com/";
23+
apiUrlPlaceholder = "https://www.bing.com";
2424
originPlaceholder = "https://www.bing.com";
2525
headers = {
2626
"Content-Type": "application/x-www-form-urlencoded",
@@ -56,7 +56,7 @@ export default class BingTranslateProvider extends BaseProvider {
5656
method,
5757
headers: {
5858
...this.headers,
59-
Referer: this.origin,
59+
Referer: `${this.origin}/translator`,
6060
Origin: this.origin,
6161
...headers,
6262
},
@@ -183,22 +183,27 @@ export default class BingTranslateProvider extends BaseProvider {
183183
}
184184

185185
const { token, ig, creationTimestamp } = await this.getSession();
186-
const translatorID = tone === "Standard" ? 5026 : 5023;
186+
const isStandardTone = tone === "Standard";
187+
const translatorID = isStandardTone ? 5026 : 5023;
187188
const params = this.getParams({
188189
isVertical: "1",
189190
IG: ig,
190191
IID: `translator.${translatorID}`,
191192
});
192193

193-
const body = new URLSearchParams([
194+
const bodyData: [string, string][] = [
194195
["fromLang", fromLang],
195196
["to", toLang],
196197
["tryFetchingGenderDebiasedTranslations", "true"],
197198
["token", token],
198199
["key", String(creationTimestamp)],
199-
["tone", tone],
200200
["text", text],
201-
]).toString();
201+
];
202+
if (!isStandardTone) {
203+
bodyData.push(["tone", tone]);
204+
}
205+
206+
const body = new URLSearchParams(bodyData).toString();
202207
const res = await this.request<TranslateSuccessResponse>(
203208
`/ttranslatev3?${params}`,
204209
body,

0 commit comments

Comments
 (0)