CopilotAIStrategy
Selected via 'strategy' => 'ai' in the plugin config – or by passing a CopilotAIStrategy instance directly. Provider credentials stay in Kirby Copilot; this plugin never talks to an AI provider itself.
'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 bytes – a single oversized unit rides alone, never split.
LLM batching preserves per-item context naturally, so table cells ride along with prose.
<cN/> KirbyTag placeholders are validated after the strategy returns, so that guarantee holds for every strategy rather than this one – see KirbyTags.
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 |
empty or non-string translation | An empty string or non-string value appeared in the response array |