CopilotAIStrategy
Translate content via any AI provider configured in Kirby Copilot – context-aware translation using OpenAI, Anthropic, Google, or Mistral.
'strategy' => 'ai' without the Copilot plugin installed throws LogicException.Behavior
Translations come back as a schema-constrained array. Chunks where the response length doesn't match the input fall back to source text. Units are packed into chunks bounded by 50 items and 100,000 characters – a single oversized unit rides alone, never split.
TranslationMode::Single is ignored. LLM batching preserves per-item context naturally, so table cells can ride along with prose.
The strategy counts <cN/> KirbyTag placeholders in source vs. translation. Mismatched units fall back to source text and trigger content-translator.translate:warning.
Construction
public function __construct(
Client|null $client = null,
string|null $systemPrompt = null,
)
Client::instance().johannschopplich.content-translator.ai.systemPrompt, then to the built-in default.Usage
return [
'johannschopplich.content-translator' => [
'strategy' => 'ai',
],
'johannschopplich.copilot' => [
'provider' => 'openai',
'providers' => [
'openai' => ['apiKey' => env('OPENAI_API_KEY')],
],
],
];
use JohannSchopplich\ContentTranslator\Translation\Strategies\CopilotAIStrategy;
use JohannSchopplich\ContentTranslator\Translator;
Translator::translateText('Hello', 'de', 'en', new CopilotAIStrategy());
use JohannSchopplich\ContentTranslator\Translation\Strategies\CopilotAIStrategy;
return [
'johannschopplich.content-translator' => [
'strategy' => new CopilotAIStrategy(
systemPrompt: 'You are a medical translator. Preserve clinical terminology and abbreviations.',
),
],
];
Drop Reasons
Each dropped unit emits a content-translator.translate:warning event with one of these reasons:
| Reason | Cause |
|---|---|
<upstream error message> | Upstream provider call threw (rate limit, network, auth) |
response length mismatch | The AI returned more or fewer translations than units sent |
non-string translation | A non-string value appeared in the response array |
placeholder count mismatch | The translation lost or invented a <cN/> KirbyTag placeholder |