Janitor Integration

Run translation commands directly from the Kirby Panel using Janitor.

While you can run Kirby commands from the CLI, you can also create a custom Kirby Janitor command to translate content and run it from the Panel.

Content Translator section with Janitor command

Blueprint Field

Create a field in your blueprint that triggers the Janitor command:

fields/janitor-translate-files.yml
label: Translate Files Metadata
type: janitor
command: janitor-translate-files --language de

Command

Create the Janitor command in your site/commands folder:

site/commands/janitor-translate-files.php
use Bnomei\Janitor;
use Kirby\CLI\CLI;

return [
    'description' => 'Translates all files metadata of a specific page.',
    'args' => [
        'language' => [
            'longPrefix' => 'language',
            'description' => 'The target language to translate the content to.',
            'required' => true
        ]
    ] + Janitor::ARGS,
    'command' => static function (CLI $cli): void {
        $kirby = $cli->kirby();
        $defaultLanguage = $kirby->defaultLanguage()->code();
        $targetLanguage = $cli->arg('language');
        $page = $kirby->page($cli->arg('page'));

        foreach ($page->files() as $file) {
            $translator = $file->translator();
            $translator->copyContent($targetLanguage, $defaultLanguage);
            $translator->translateContent($targetLanguage, $targetLanguage, $defaultLanguage);
        }

        Janitor::singleton()->data($cli->arg('command'), [
            'status' => 200,
            'message' => 'Files translated successfully!'
        ]);
    }
];

The command receives the current page context from Janitor, making it easy to create page-specific translation buttons in your blueprints.