DeepLStrategy

Translate via DeepL with automatic batching and retries – the default strategy when nothing else is configured.

Selected automatically when neither strategy nor the deprecated translateFn is configured. Inject a custom DeepL client to override language mapping or stub it out in tests.

Behavior

The whole batch fails together: when DeepL rejects the request, every unit fires content-translator.translate:warning and TranslationException is thrown.

Selected via 'strategy' => 'deepl'. Also the last-resort default – chosen whether or not DeepL.apiKey is set; a missing key surfaces as AuthException on the first translation.

Construction

public function __construct(DeepL|null $deepL = null)
deepL
DeepL | null
Inject a custom DeepL client – useful in tests or when you want non-singleton instances. Defaults to DeepL::instance().

Usage

site/config/config.php
return [
    'johannschopplich.content-translator' => [
        'strategy' => 'deepl',
        'DeepL' => [
            'apiKey' => 'your-deepl-api-key',
        ],
    ],
];
Build strategy instances inside Kirby's ready callback; at the top level of config.php the plugin options are not readable yet, so new DeepL() throws AuthException: Missing DeepL API key even though the key sits right next to it.
For request-option tuning (formality, glossary IDs, custom tag_handling), see the DeepL client reference.