1. Go to this page and download the library: Download statikbe/craft-deepl 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/ */
use DeepL\TranslateTextOptions;
use statikbe\deepl\events\ModifyTranslateOptionsEvent;
use statikbe\deepl\services\ApiService;
use yii\base\Event;
Event::on(
ApiService::class,
ApiService::EVENT_BEFORE_TRANSLATE,
function (ModifyTranslateOptionsEvent $event) {
if ($event->targetLang === 'fr') {
$event->customInstructions[] = 'Use a friendly, informal tone (tutoiement).';
$event->customInstructions[] = 'Translate brand names literally; do not localize.';
}
// Or set any other DeepL option directly:
$event->options[TranslateTextOptions::FORMALITY] = 'less';
}
);