Skip to content

Commit

Permalink
Fixes 400 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dala0 committed Jul 23, 2019
1 parent 2ad0de0 commit 5e31e97
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/Stichoza/GoogleTranslate/TranslateClient.php
Original file line number Diff line number Diff line change
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 5e31e97

Please sign in to comment.