PHP code example of mistralys / deepl-xml-translator

1. Go to this page and download the library: Download mistralys/deepl-xml-translator 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/ */

    

mistralys / deepl-xml-translator example snippets


$translator = new \DeeplXML\Translator(
    'YourAPIKey', // the DeepL API key to use to connect
    'EN', // source language
    'DE' // target language
); 

$translator->addString('string1', 'Please translate me');
$translator->addString('string2', 'Please also translate me');

try
{
    $translator->translate();
}
catch(\DeeplXML\Translator_Exception $e)
{
    // handle errors
}    

$strings = $translator->getStrings();

 foreach($strings as $string)
 {
     $text = $string->getTranslatedText();
 }

$string = $translator->getStringByID('string2');
$text = $string->getTranslatedText();

$string = $translator->addString('string1', 'Please ignore me');

// the text "ignore" will not be translated in the string
$string->addIgnoreString('ignore');


$api = $translator->getConnector();

// do something with it