Closed murat-ti closed 1 year ago
Ok, got the problem. I'll rename this issue if you don't mind
Replicated the error. It definitely throws an exception. I checked the website and saw that Google is sending a new xid
parameter. I copied it from devtools and added it to a query parameter
'xid' => 1782844, // Value copied from Google Translate network logs
It fixed the problem you described.
Now I need to figure out how the xid
value is generated. Any help appreciated.
Excerpt from translate_m.js
on Google Translate website:
var Nu = function(a) {
var b = (new Wm(n.location.href)).a,
c = b.get("e"),
d = b.get("expid");
b = b.get("expflags");
var e = "";
if (b)
return "expflags=" + b;
c && (e += "e=" + c);
d && (e && (e += "&"), e += "expid=" + d);
a.b.length && (e && (e += "&"), e += "xid=" + a.b.join());
return e
},
Thank you for your quick reply, currently I decided to use static value in my project. I try understand how xid value is generating in previous answer, but can not find values as "e" and "expid" in result generated url.
The Nu
function gets called like this:
... where this.na
holds an Iu
object with a b
parameter, that is an array containing this "mystic" value. In this scope this
refers to a PM
object. If we inspect what happens when a PM
object is created:
... on line 30026 it looks like the Iu
object that this.na
is set to, gets a parameter, which is an array of "triggered experiment ids".
So it looks like this is just some kind of internal id of an "experiment" that G is running right now (and this is what xid
is referring to). Later I also verified this when I found it in the source code of the page:
--
Further inspections: I've set a breakpoint on the first line of the Nu
function and tried removing the magical number before setting it in the request. When I removed it and I translated a string from English to German, the translation was successful, but on an English to Turkmen translation, it failed, so it looks like the experiment id is required for the new (experimental?) language translations. Maybe for G to log some things, initialize other modules.
For me, this means that we should keep our eyes on the new languages and look for experiment ids, as they may change a couple of times in the near future until G decides to make them permanent.
Where and how to add this parameter 'xid' => 1782844?
Where and how to add this parameter 'xid' => 1782844?
Hi, You need find GoogleTranslate.php, which is located in "yourproject\vendor\stichoza\google-translate-php\src\GoogleTranslate.php". Go to the getResponse(string $string) function, which is located on 290 line and xid parameter like that: $queryArray = array_merge($this->urlParams, [ 'sl' => $this->source, 'tl' => $this->target, 'tk' => $this->tokenProvider->generateToken($this->source, $this->target, $string), 'q' => $string, 'xid' => 1782844, ]);
Hello,
I'm currently facing the same issue. Did you have the chance to solve this issue?
Regards, Gabor
@gaborivanyiczki Did you find the solution? I am facing the same problem!
Did you find the solution? I am facing the same problem! for Myanmar and chinese language Please give me answer
@heinminhtet8138 Mine was because of sanction, I changed the server and problem solved.
any update?
Seems to be working. Added a separate test in 0d921190901165605c5a673f3d0df13fd89b96dc to check translations.
Google Translate throws ErrorException with 400 Bad Request when translating to languages like Turkmen (
tk
), etc.Original issue content
Exception 'ErrorException' with message 'Client error:
GET https://translate.google.com/translate_a/single?client=webapp&hl=en&dt=t&dt=bd&dt=at&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&sl=ru&tl=tk&q=%D0%A0%D0%BE%D0%B7%D1%8B%D0%B3%D1%80%D1%8B%D1%88+%D0%B2+Ada+kafe&ie=UTF-8&oe=UTF-8&multires=1&otf=0&pc=1&trs=1&ssel=0&tsel=0&kc=1&tk=592424.997718
resulted in a400 Bad Request
response: