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',
],
],
];
use JohannSchopplich\ContentTranslator\Translation\Strategies\DeepLStrategy;
use JohannSchopplich\ContentTranslator\Translator;
Translator::translateText('Hello', 'de', 'en', new DeepLStrategy());
site/config/config.php
use JohannSchopplich\ContentTranslator\DeepL;
use JohannSchopplich\ContentTranslator\Translation\Strategies\DeepLStrategy;
return [
'ready' => fn () => [
'johannschopplich.content-translator' => [
'strategy' => new DeepLStrategy(new DeepL()),
],
],
];
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.