Skip to content

Commit

Permalink
Merge pull request #114 from Dala0/fix_400_errors
Browse files Browse the repository at this point in the history
Fixes 400 BadRequest Errors For Old 3.2 Branch
  • Loading branch information
Stichoza committed Oct 29, 2019
2 parents 2ad0de0 + 5e31e97 commit a12ff84
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/Stichoza/GoogleTranslate/TranslateClient.php
Expand Up @@ -67,7 +67,7 @@ class TranslateClient
* @var array URL Parameters
*/
private $urlParams = [
'client' => 't',
'client' => 'webapp',
'hl' => 'en',
'dt' => 't',
'sl' => null, // Source language
Expand Down Expand Up @@ -305,20 +305,14 @@ private function getResponse($data)
'sl' => $this->sourceLanguage,
'tl' => $this->targetLanguage,
'tk' => $this->tokenProvider->generateToken($this->sourceLanguage, $this->targetLanguage, $tokenData),
'q' => $tokenData
]);

$queryUrl = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($queryArray));

$queryBodyArray = [
'q' => $data,
];

$queryBodyEncoded = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($queryBodyArray));

try {
$response = $this->httpClient->post($this->urlBase, [
$response = $this->httpClient->get($this->urlBase, [
'query' => $queryUrl,
'body' => $queryBodyEncoded,
] + $this->httpOptions);
} catch (GuzzleRequestException $e) {
throw new ErrorException($e->getMessage());
Expand Down

0 comments on commit a12ff84

Please sign in to comment.