CopilotAIStrategy

Context-aware AI translation through any Copilot provider – batched, validated, and resilient to malformed model responses.

Translate content via any AI provider configured in Kirby Copilot – context-aware translation using OpenAI, Anthropic, Google, or Mistral.

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.

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
\\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')],
        ],
    ],
];
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:

ReasonCause
<upstream error message>Upstream provider call threw (rate limit, network, auth)
response length mismatchThe AI returned more or fewer translations than units sent
non-string translationA non-string value appeared in the response array
placeholder count mismatchThe translation lost or invented a <cN/> KirbyTag placeholder
Wire content-translator.translate:warning to logging or alerting to surface drops in production.