PHP code example of babymarkt / deepl-php-lib

1. Go to this page and download the library: Download babymarkt/deepl-php-lib 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/ */

    

babymarkt / deepl-php-lib example snippets


use \BabyMarkt\DeepL\DeepL;

$authKey = '<AUTH KEY>';
$deepl   = new DeepL($authKey);

use \BabyMarkt\DeepL\DeepL;

$authKey = '<AUTH KEY>';
$deepl   = new DeepL($authKey,2,'api-free.deepl.com');

$translatedText = $deepl->translate('Hallo Welt', 'de', 'en');
echo $translatedText[0]['text'].PHP_EOL;

$text = array(
    'Hallo Welt',
    'Wie geht es dir',
    'Macht doch einfach mal'
);

$translations = $deepl->translate($text, 'de', 'en');

foreach ($translations as $translation) {
    echo $translation['text'].PHP_EOL;
}

$languagesArray = $deepl->languages();

foreach ($languagesArray as $language) {
    echo 'Name: '.$language['name'].' Api-Shorthand: '.$language['language'].PHP_EOL;
}

$sourceLanguagesArray = $deepl->languages('source');

foreach ($sourceLanguagesArray as $sourceLanguage) {
    echo 'Name: '.$sourceLanguage['name'].' Api-shorthand: '.$sourceLanguage['language'].PHP_EOL;
}

$targetLanguagesArray = $deepl->languages('target');

foreach ($targetLanguagesArray as $targetLanguage) {
    echo 'Name: '.$targetLanguage['name'].' Api-Shorthand: '.$targetLanguage['language'].PHP_EOL;
}

$usageArray = $deepl->usage();

echo 'You have used '.$usageArray['character_count'].' of '.$usageArray['character_limit'].' in the current billing period.'.PHP_EOL;


$glossary = $deepl->createGlossary('MyGlossary', ['Hallo' => 'Hello'], 'de', 'en');

$glossary = $deepl->deleteGlossary($glossaryId);

use \BabyMarkt\DeepL\Glossary;

$glossaries = $deepl->listGlossaries();
foreach ($glossaries as $glossary) {
    var_dump($glossary);
}

use \BabyMarkt\DeepL\Glossary;

$glossaryInformation = $deepl->glossaryInformation($glossaryId);
var_dump($glossaryInformation);

$entries = $deepl->glossaryEntries($glossaryId);
foreach ($entries as $sourceLangText => $targetLangText) {
    echo $sourceLangText .' > '.$targetLangText;
}

$deepl->setTimeout(10); //give up after 10 seconds
$deepl->setProxy('http://corporate-proxy.com:3128');
$deepl->setProxyCredentials('username:password');

bash
composer