PHP code example of octfx / deeply

1. Go to this page and download the library: Download octfx/deeply library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

octfx / deeply example snippets


$deepLy = new Octfx\DeepLy\DeepLy('Your-API-Key');

$translatedText = $deepLy->translate('Hello world!', 'DE', 'EN');
    
echo $translatedText; // Prints "Hallo Welt!"

use Octfx\DeepLy\DeepLy;

$apiKey = 'Your-API-Key';
$deepLy = new DeepLy($apiKey);

try {
    $translatedText = $deepLy->translate('Hello world!', DeepLy::LANG_EN, DeepLy::LANG_AUTO);
    
    echo $translatedText; // Prints "Hallo Welt!"
} catch (AuthenticationException $e) {
    // API Key invalid
    // Code 403
} catch (QuotaException $e) {
    // Quota exceeded
    // Code 456
} catch (RateLimitedException $e) {
    // Ratelimited
    // Code 429
} catch (TextLengthException $e) {
     // Textlength > 30000 chars
} catch (CallException $e) {
    // Other errors
    // See: https://www.deepl.com/docs-api.html?part=accessing
}

$deepLy->formality('less');

// or
$translatedText = $deepLy->translate('Hello world!', DeepLy::LANG_EN, DeepLy::LANG_AUTO, 'more');

$languageCode = $deepLy->detectLanguage('Hello world!');

$deepLy->getSupportedLanguages('source'); // all supported source languages
$deepLy->getSupportedLanguages('target'); // all supported target languages

return [
    'deepl' => [
        'auth_key' => env('DEEPL_AUTH_KEY'),
    ],
];