aidanwelch / google-translate-api Goto Github PK
View Code? Open in Web Editor NEWThis project forked from vitalets/google-translate-api
An updated free and unlimited API for Google Translate :dollar: :no_entry_sign:
License: MIT License
This project forked from vitalets/google-translate-api
An updated free and unlimited API for Google Translate :dollar: :no_entry_sign:
License: MIT License
this "https-proxy-agent" is not support with react native. Could you give any suggestions?
Anyone have more info on this?
error: node_modules/google-translate-api-x/lib/Translator.cjs: /home/nirali/Desktop/farmerAssistantApp/node_modules/google-translate-api-x/lib/Translator.cjs: Class private methods are not enabled. Please add @babel/plugin-proposal-private-methods
to your configuration.
/root/***/node_modules/google-translate-api-x/lib/defaults.cjs:9
requestFunction: fetch,
^
ReferenceError: fetch is not defined
at Object.<anonymous> (/root/***/node_modules/google-translate-api-x/lib/defaults.cjs:9:19)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/root/***/node_modules/google-translate-api-x/lib/translate.cjs:2:29)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
Hi im not getting the same result when i translate in google translate and using google-translate-api.
What might be the issue?
Is there to obtain the synonyms of a word translation. For example, let's say the preposition mit in German, which can be in multiple ways in English. Is there to obtain all of those possible translations?
Thanks!
TS2339: Property 'text' does not exist on type 'ITranslateResponse | ITranslateResponse[] | { [x: string]: ITranslateResponse; }'. Property 'text' does not exist on type 'ITranslateResponse[]'.
I use React and TypeScript.
const translator = new Translator({from: 'en', to: 'es', forceBatch: false, tld: 'es'}); const res = await translator.translate('Ik spreek Engels', {to: user_data!.lang}); console.log(res.text)
@AidanWelch This package works fine when I start my server in terminal, but as soon as I deploy to Render it says ERROR ReferenceError: fetch is not defined at Object.requestFunction (/opt/render/project/src/node_modules/google-translate-api-x/lib/defaults.cjs:9:36)
, seems it isn't truly cross-platform or is there something I could do different to get it to work in a pure Node environment?
All the help will be appreciated and the batching feature is truly an improvement on the vitalets package. Thank you! ✨
The error:
TypeError: google_translate_api_x__WEBPACK_IMPORTED_MODULE_1__ is not a function
I've tried using this library on vanilla js and it works just fine. But when I tried it on React it keeps getting error like in the above even I use the simpliest method to use this library. Is there any settings that I have to apply first in my React project before using this library?
Sorry for my english and I'm new to React and JavaScript, so it will be so kind of you if you can give me an assistance.
Btw, thanks for providing this library
The codes ran fine that last time I tested, about a month or so ago. And then, in my regression test today, it starts giving the above error.
Does anyone have any idea?
Hi @AidanWelch
I caught a new error from the below codes.
trInput is an array for batch translation.
It doesn't happen all the time, maybe 1 out of 4 or 5 times. Even when all the variable values are exactly the same for all the 4 or 5 times.
const translation = await translate(trInput, {from: userLanguage, to: addHelperLanguage && helperLanguage, autoCorrect: true})
.catch((error) => {
console.error('translate| translate-google-api-x error: ', error.message)
throw error
});
Error caught in below
translate| translate-google-api-x error: Cannot read properties of null (reading '1')
Url: https://translate.google.com/_/TranslateWebserverUi/data/batchexecute?rpcids=MkEWBc&source-path=%2F&f.sid=3998618730767360818&bl=boq_translate-webserver_20230409.08_p0&hl=en-US&soc-app=1&soc-platform=1&soc-device=1&_reqid=7749&rt=c
The value returned from the Url in the error in below
)]}'
103
[["er",null,null,null,null,405,null,null,null,9],["di",17],["af.httprm",17,"-2930294764364961249",6]]
25
[["e",4,null,null,139]]
code:
const tunnel = require('tunnel');
const translate = require('google-translate-api-x');
translate('Ik spreek Engels', { to: 'en', tld: 'jp' }, {
agent: tunnel.httpsOverHttp({
proxy: {
host: '127.0.0.1', // ip
port: '7890', // port
}
}
)
}).then(res => {
console.log(res)
// do something
});
console:
PS C:\Users\Administrator\Desktop\NodejsProjects> node .
node:internal/deps/undici/undici:14062
Error.captureStackTrace(err, this);
^
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:14062:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async runBatch (C:\Users\Administrator\Desktop\NodejsProjects\node_modules\google-translate-api-x\lib\translate.cjs:7:19) {
cause: ConnectTimeoutError: Connect Timeout Error
at onConnectTimeout (node:internal/deps/undici/undici:7897:28)
at node:internal/deps/undici/undici:7855:50
at Immediate._onImmediate (node:internal/deps/undici/undici:7884:37)
at process.processImmediate (node:internal/timers:471:21) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
}
Node.js v18.13.0
Issue 12 wasn't finished being addressed before it was closed. My app wouldn't hit the rate limit as it sends fewer than 20 requests per day.
Error code 429 is a "too many requests" error. I would assume that your API has a Google Translate API key tied to it? My immediate thought is there are too many users on this "free api" causing the interface to hit the rate limit.
Certain networks require the X-Goog-BatchExecute-Bgr
header to be sent on requests, or the autocorrect will not be applied to some translations(seemingly typos where a letter is dropped, such as "I spea Dutch!" instead of "I speak Dutch!").
The code for generating this header I believe is found in this static script.
I believe in xH.prototype.s()
This would likely take a while to fix.
I'm using ReactJs.
When I use the request example. I'm getting CORS error.
import translate from 'google-translate-api-x';
const res = await translate('Ik spreek Engels', { to: 'en' });
console.log(res.text); //=> I speak English
console.log(res.from.language.iso); //=> nl
That code return
Access to fetch at 'https://translate.google.com/' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Is that an API error or I need to use some param on the request translate()
?
Error Info
Partial Translation Request Fail: at least one translation failed, it was either invalid or more likely- rejected by the server. You can try the request again and if it persists try a proxy, spacing out requests, and/or using a different tld. If you would like to translate other requests in a batch translation even if one fails(the failed translation will be set to
null
) pass the optionrejectOnPartialFail: false
. You can also try using the singleTranslate endpoint with:forceBatch: false
A reproducible example
https://runkit.com/eyelly/64787340c932b600084ae8ee
Thanks to the author for providing this tool library, hope this problem can be fixed
is there any way to change the speak (tts) speed? its talking a bit slow
i installed your package and tried the description but unfortunately i get errors about CORS error, and i don't know how to solve it
I want to pass an array of string for translation. Could you help support it?
Is there interest in the Fetch and Axios versions being combined, with auto and manual detection?
Use proxy or pretest for access first (or if there's another solution
Most languages default to masculine, so it shouldn't return feminine just because that is what Google Translate lists first, because in the Google Translate UI that is properly represented
Can this package translate in real-time, like users don't need to press the translate button to translate, but just need to type and wait for it to auto translate?
Hello, I am getting the error in the title while translating text. I suspected it because I was using texts dynamically. Then I tried to translate the texts statically but this error returns 1 time out of 5 translations (same text).
Hi @AidanWelch, thanks for an amazing package!
One thing I noticed in the past day or two is that a big translation (like full song lyrics) considerably slowed down. It used to be almost instant, but now it's taking up to 15 seconds.
When I try vitalets package, it is still almost instant. Do you know of any reason this might be happening?
I'm using a Next.js project, still on Next 12 using an API route (server side). Is there any way to test the speed of the actual package? Thanks!
New to development,
I am getting this error
/node_modules/google-translate-api-x/lib/speak.cjs:66 const result = JSON.parse(translation[2])[0]; ^ TypeError: Cannot read properties of null (reading '0')
I figured it out , the issue appears when the text under single translate using "speak" function exceeds 195 characters.
I need help how to convert long texts to mp3.
There are other packages that are able to convert it, but I really wanted to make this package more efficient by adding inputs.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.