CopilotAIStrategy
Context-aware AI translation through any Copilot provider – batched, validated, and resilient to malformed model responses.
Selected via 'strategy' => 'ai' in your Kirby Copilot config – or by passing a CopilotAIStrategy instance directly.
Selecting
'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.
LLM batching preserves per-item context naturally, so table cells 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
\\JohannSchopplich\\Copilot\\AI\\Client | null
Inject a Copilot client. Defaults to
Client::instance().systemPrompt
String | null
Override the system prompt for this instance. Falls back to
johannschopplich.content-translator.ai.systemPrompt, then to the built-in default.Usage
config.php
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.',
),
],
];
For the full default system prompt and a copy-paste-safe customization template, see the AI Translation docs.
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 |