CopilotAIStrategy
Context-aware AI translation through any Copilot provider – batched, validated, and resilient to malformed model responses.
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.
Selecting
'strategy' => 'ai' without the Copilot plugin installed throws LogicException.Behavior
Units are sent in batches; a batch whose response is malformed keeps its source text and is reported as rejections.
<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
\\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
site/config/config.php
return [
'johannschopplich.content-translator' => [
'strategy' => 'ai',
],
'johannschopplich.copilot' => [
'provider' => 'openai',
'providers' => [
'openai' => ['apiKey' => 'your-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.
Rejection Reasons
Each rejected unit emits a content-translator.translate:warning event.