Migration

Upgrade notes for breaking and notable changes between versions.

Migrating From v3 to v4

Breaking Change: Kirby Content Translator v4 runs on the current Kirby major and PHP 8.3 or later, and the section becomes a field. The license compatibility page lists which plugin version runs on which Kirby version.

The Section Is a Field

Move contentTranslator from sections: to fields:. The type and every property keep their names:

site/blueprints/pages/default.yml
-sections:
+fields:
   contentTranslator:
     type: content-translator
     title: true

A content-translator entry left under sections: shows Kirby's "Invalid section type" box in its place. See Field Configuration.

confirm Is Removed

The confirm option is gone from the view button, the field, and the global configuration. Import fills the current language on the first click, without a confirmation dialog. A leftover confirm key has no effect.

fieldTypes Names the Picker Fields

Kirby resolves the pages, files, and users field types to pagepicker, filepicker, and userpicker, so a fieldTypes list that names pages, files, or users matches nothing. List the new names instead:

site/config/config.php
 return [
     'johannschopplich.content-translator' => [
-        'fieldTypes' => ['text', 'textarea', 'pages'],
+        'fieldTypes' => ['text', 'textarea', 'pagepicker'],
     ],
 ];

translateFn Is Removed

A config that still sets translateFn throws a LogicException. Rename the key to strategy – the closure signature is identical:

site/config/config.php
 return [
     'johannschopplich.content-translator' => [
-        'translateFn' => function (string $text, string $target, ?string $source) { /* … */ },
+        'strategy' => function (string $text, string $target, ?string $source) { /* … */ },
     ],
 ];

copyContent() Keeps the Target's Slug and Other Fields

Copying from the default language no longer deletes the target language's content. copyContent() writes the source's eligible fields and a page's or the site's title, from any source language. The target keeps its slug and every other field's value, and no longer follows later edits in the default language.

Rejection Reasons Are an Enum

reason in the translate:warning hook and TranslationRejection::$reason in the translation result are cases of the JohannSchopplich\ContentTranslator\Translation\TranslationRejectionReason enum. Compare against a case, or read the string through ->value:

site/config/config.php
+use JohannSchopplich\ContentTranslator\Translation\TranslationRejectionReason;
+
 return [
     'hooks' => [
         'content-translator.translate:warning' => function ($unit, $reason, $previous) {
-            if ($reason === 'placeholder mismatch') {
+            if ($reason === TranslationRejectionReason::PlaceholderMismatch) {
                 // …
             }
-            error_log('Translation rejected: ' . $reason);
+            error_log('Translation rejected: ' . $reason->value);
         },
     ],
 ];

A DeepL or Copilot AI failure no longer reports the provider's message as the reason. It arrives as ProviderError, with the provider's exception in previous. A custom strategy that fires the hook itself passes a case too.

Content Kirby's YAML Parser Reads Differently

Kirby reads YAML with Symfony YAML, and the plugin decodes structure, object, and table content through it. Content Kirby saved with Spyc can read differently there: an unquoted date such as 2024-01-01 turns into a number, which a translation then saves in its place, and a value starting with @ cannot be parsed at all, so translating the model throws, as does opening it in the Panel. If your content has either, switch Kirby back to Spyc:

site/config/config.php
return [
    'yaml.handler' => 'spyc',
];

Migrating to v3.17 (KirbyText Removal)

JohannSchopplich\ContentTranslator\KirbyText::translateText() is removed. Migrate to Translator::translateText() – the diff under v3.11 shows the change.

Migrating to v3.16 (Nested Field Keys)

TranslationUnit::$fieldKey now leads with the container for a field inside a structure, object, blocks, or layout field: body.text where v3.15 reported text. Top-level fields are unchanged. A translate:warning handler that matches nested field names needs the new form.

Migrating to v3.14 (Rejection Reasons)

The reasons the translate:warning hook reports were renamed. A handler matching the old strings stops matching.

BeforeAfter
placeholder count mismatchplaceholder mismatch
empty or non-string translationempty translation, non-string translation

missing translation is new. A strategy returning fewer entries than it was given units used to be rejected silently.

For custom strategies, an empty string is now a failed unit rather than a translation, so the field keeps its source text instead of being blanked.

Migrating to v3.11 (Strategy Refactor)

v3.11 introduces a typed Strategy interface and a unified strategy config option. No breaking changes – existing code keeps working unchanged. Two deprecations:

  • johannschopplich.content-translator.translateFn – migrate to 'strategy' => $closure. Signature is identical. Removed in v4.
  • JohannSchopplich\ContentTranslator\KirbyText::translateText() – migrate to Translator::translateText(). Removed in v3.17.

translateFn → strategy

site/config/config.php
 return [
     'johannschopplich.content-translator' => [
-        'translateFn' => function (string $text, string $target, ?string $source) { /* … */ },
+        'strategy' => function (string $text, string $target, ?string $source) { /* … */ },
     ],
 ];

When both keys are set, strategy wins.

KirbyText::translateText() → Translator::translateText()

-use JohannSchopplich\ContentTranslator\KirbyText;
-$translated = KirbyText::translateText($text, 'de', 'en', $kirbyTags);
+use JohannSchopplich\ContentTranslator\Translator;
+$translated = Translator::translateText($text, 'de', 'en');

Translator::translateText() routes through the configured strategy but translates the string as plain text – KirbyTags in it are not protected. Text with KirbyTags keeps them intact when it is translated as a textarea field through translateContent(), which applies the kirbyTags option.

For the new architecture, see PHP Classes → Strategies.