The most common use case is to copy the content from the default language to a secondary language and then translate the duplicated content to the target language.
Install the Kirby CLI and create a site/commands folder if it does not exist yet.
use Kirby\CLI\CLI;
return [
'description' => 'Translates the content of a specific page.',
'args' => [
'language' => [
'description' => 'The target language to translate the content to.',
'defaultValue' => 'de'
]
],
'command' => static function (CLI $cli): void {
$kirby = $cli->kirby();
$defaultLanguage = $kirby->defaultLanguage()->code();
$targetLanguage = $cli->arg('language');
$siteChildren = $kirby->site()->children();
$input = $cli->radio(
'Which page should be translated?',
$siteChildren->pluck('title')
);
$response = $input->prompt();
$cli->success('Selected page: ' . $response);
$page = $siteChildren->findBy('title', $response);
$translator = $page->translator();
$translator->copyContent($targetLanguage, $defaultLanguage);
$translator->translateContent($targetLanguage, $targetLanguage, $defaultLanguage);
$cli->success('Successfully translated ' . $page->id());
}
];
# Translate the content of a specific page to German
kirby translate-page de