Copy content to translated page

Hi there,

I am wondering, if there is a way to copy all contents of a page to its translation from within the panel. Maybe someone knows a way?

Thank you very much in advance!

Sigi

Maybe with a Janitor button and a custom job: Janitor | Kirby CMS. Make sure not to overwrite existing translations, though.

Thank you, I will look into that.

I think, the solution with the Janitor Plugin works, but I have issues with achieving what I want with my code. Maybe someone sees what’s wrong here?

'bnomei.janitor.jobs' => [
    'copy' => function (Kirby\Cms\Page $page = null, string $data = null) {
        if ($page === null) {
          $page = site()->index(true)->findByID($data); 
        }
        $languages = kirby()->languages();
        $content = $page->text();
        $translation = page($page->uri($languages->not(kirby()->language())->first()->code()));
        $translation = $translation->update(['text' => $content]);
        return [
            'status' => 200,
            'label' => 'Kopiert.',
        ];
    },
  ],

A translation doesn’t exist as a separate page. You update a translation by updating the page and passing the language code as second parameter:

For example, update all non-default languages:

$languages = kirby()->languages()->not(kirby()->defaultLanguage());
foreach ( $languages as $language ) {
  $page->update(
    [
      'text' => $content
    ], 
    $language->code()
  );
}

Thank you very much, that’s it and also explains a lot.
Is there a way to mark both of your answers as solutions?

No, there is always only one solution here.