Created
April 25, 2019 17:09
-
-
Save caugner/337931f83752d128579c24f5a083eff1 to your computer and use it in GitHub Desktop.
deepl-translate-multiple-texts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use GuzzleHttp\Client as HttpClient; | |
use GuzzleHttp\Exception\GuzzleException; | |
require_once 'vendor/autoload.php'; | |
$input = ["Hallo", "Welt"]; | |
print_r($input); | |
try { | |
$httpClient = new HttpClient([ 'base_uri' => 'https://api.deepl.com/v2/']); | |
$response = $httpClient->request('POST', 'translate', [ | |
'form_params' => [ | |
'text' => $input, | |
'source_lang' => "DE", | |
'target_lang' => "EN", | |
'split_sentences' => 0, | |
'preserve_formatting' => 0, | |
'auth_key' => "***" | |
], | |
]); | |
$json = $response->getBody()->getContents(); | |
$result = json_decode($json, true); | |
$output = array_column($result['translations'], 'text'); | |
print_r($output); | |
} catch (GuzzleException $e) { | |
echo $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yemanjo thank you very much - with json it works :)