Skip to content

Commit 52959a6

Browse files
committed
feat: too many request fix
1 parent 281cc73 commit 52959a6

File tree

3 files changed

+196
-80
lines changed

3 files changed

+196
-80
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.5.0",
2+
"version": "1.5.1",
33
"license": "MIT",
44
"main": "dist/index.js",
55
"description": "Translate your JSON file or object into another languages with Google Translate API",
@@ -65,7 +65,7 @@
6565
"dependencies": {
6666
"@types/bluebird": "^3.5.36",
6767
"@types/filesystem": "^0.0.32",
68-
"@vitalets/google-translate-api": "^9.0.0",
68+
"@vitalets/google-translate-api": "8.0.0",
6969
"axios": "^1.2.2",
7070
"bluebird": "^3.7.2",
7171
"cwait": "^1.1.2",

src/core/core.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { translate } from '@vitalets/google-translate-api';
1+
import translate from '@vitalets/google-translate-api';
22
import createHttpProxyAgent from 'http-proxy-agent';
33
import { LanguageCode, Sources } from '..';
44
import * as fs from 'fs/promises';
@@ -113,13 +113,18 @@ async function translateWithGoogle(
113113
word: string,
114114
from: LanguageCode,
115115
to: LanguageCode,
116-
options?: any
116+
options?: { agent: any; timeout: number }
117117
) {
118-
const { text } = await translate(safeValueTransition(word), {
119-
from: from,
120-
to: to,
121-
fetchOptions: options,
122-
});
118+
const { text } = await translate(
119+
safeValueTransition(word),
120+
{
121+
from: from,
122+
to: to,
123+
},
124+
{
125+
agent: options != undefined ? options.agent : undefined,
126+
}
127+
);
123128

124129
global.totalTranslated = global.totalTranslated + 1;
125130

0 commit comments

Comments
 (0)