Skip to content

Instantly share code, notes, and snippets.

@caugner
Created April 25, 2019 17:09
Show Gist options
  • Save caugner/337931f83752d128579c24f5a083eff1 to your computer and use it in GitHub Desktop.
Save caugner/337931f83752d128579c24f5a083eff1 to your computer and use it in GitHub Desktop.
deepl-translate-multiple-texts
<?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();
}
@renepardon
Copy link

@yemanjo thank you very much - with json it works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment