How to Translate Text Between English and French in PHP
Good translation services can help increase the breadth of a product/app’s customer base. Thankfully, using the complementary, ready-to-run PHP code examples below, you can quickly and easily implement free English to French & French to English translation APIs in minutes. These resources both use advanced Deep Learning and Neural NLP, ensuring fast and accurate translations for all of your needs.
To install the PHP client using composer, execute this command from the command line:
composer require cloudmersive/cloudmersive_nlp_api_client
Next, copy from the below examples to structure your English to French API call:
<?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->languageTranslationTranslateEngToFra($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling LanguageTranslationApi->languageTranslationTranslateEngToFra: ', $e->getMessage(), PHP_EOL;
}
?>
Finally, copy from the below to structure your French to English API call:
<?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->languageTranslationTranslateFraToEng($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling LanguageTranslationApi->languageTranslationTranslateFraToEng: ', $e->getMessage(), PHP_EOL;
}
?>
All done! To authenticate each call for free, register a free account on our website to get your free-tier API key (this provides a limit of 800 API calls per month & no additional commitments).