translate-variable icon indicating copy to clipboard operation
translate-variable copied to clipboard

问题咨询

Open yangql176 opened this issue 1 year ago • 2 comments

嗨 您好,我在调研项目国际化的过程中看到了您的vscode插件,有个问题想要咨询您下:

我看您的插件里用到了Google翻译 我发现好像是不用任何appKey就可以直接使用的,我本身也有梯子 所以您的插件本身使用没有问题,但我在本地用和您一样的引入和用法却总是不能用,总是在报FetchError: Invalid response body while trying to fetch https://translate.google.com/translate_a/single?client=at&dt=t&dt=rm&dj=1: read ECONNRESET

非常非常偶尔才可以正确输出翻译内容 想问下这个是怎么回事呢

yangql176 avatar May 14 '24 09:05 yangql176

嗨 您好,我在调研项目国际化的过程中看到了您的vscode插件,有个问题想要咨询您下:

我看您的插件里用到了Google翻译 我发现好像是不用任何appKey就可以直接使用的,我本身也有梯子 所以您的插件本身使用没有问题,但我在本地用和您一样的引入和用法却总是不能用,总是在报FetchError: Invalid response body while trying to fetch https://translate.google.com/translate_a/single?client=at&dt=t&dt=rm&dj=1: read ECONNRESET

非常非常偶尔才可以正确输出翻译内容 想问下这个是怎么回事呢

应该是谷歌这边的限制,限制不能发送太多请求,可参考一下库这边的处理,https://github.com/vitalets/google-translate-api?tab=readme-ov-file#limits

Kerinlin avatar May 15 '24 06:05 Kerinlin

import { translate } from '@vitalets/google-translate-api';
import { HttpProxyAgent } from 'http-proxy-agent';

const agent = new HttpProxyAgent('http://212.107.29.43:80');
const res = await translate('Привет, мир!', {
  to: 'en',
  fetchOptions: { agent },
});

Kerinlin avatar May 15 '24 06:05 Kerinlin