How to Translate Between English and German in PHP
Our NLP API endpoint makes it easy to translate text between several languages — including English and German — with just a few lines of code.
To quickly implement English to German & German to English translation services into your application, just follow steps below to copy & paste from complementary, ready-to-run PHP code examples. Our APIs use advanced deep learning and Neural NLP to create useful, accurate translations in moments. After that, register a free account on our website to get a free-tier API key, and you’ll be ready to start translating in minutes.
First things first — let’s run the below command to install the client SDK:
composer require cloudmersive/cloudmersive_nlp_api_client
After that, let’s copy the following code examples to structure our request for English to German translation:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');
$apiInstance = new Swagger\Client\Api\LanguageTranslationApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$input = new \Swagger\Client\Model\LanguageTranslationRequest(); // \Swagger\Client\Model\LanguageTranslationRequest | Input translation request
try {
$result = $apiInstance->languageTranslationTranslateEngToDeu($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling LanguageTranslationApi->languageTranslationTranslateEngToDeu: ', $e->getMessage(), PHP_EOL;
}
?>
And to translate from German to English, let’s use the following examples instead:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');
$apiInstance = new Swagger\Client\Api\LanguageTranslationApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$input = new \Swagger\Client\Model\LanguageTranslationRequest(); // \Swagger\Client\Model\LanguageTranslationRequest | Input translation request
try {
$result = $apiInstance->languageTranslationTranslateDeuToEng($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling LanguageTranslationApi->languageTranslationTranslateDeuToEng: ', $e->getMessage(), PHP_EOL;
}
?>
Yep, that’s really all the code you’ll need. Viel Spaß beim einfachen Übersetzen!