Copy content from one language to another

What would be the best way to copy a sturcture feild from one language content to another?

I have a site in two lanaguages, and the structure feild content is the same in both languages. When i save the page in the panel im guessing I can use a hook to copy it over to the other language or vice versa.

However, i cant see anything in the docs that lets me get hold of the current lanuage the user in the panel is using so i know which way to copy it.

How would i do that?

Hey,

isn’t it the perfect use case for a field option translate → false?

Thanks for the tip… im not sure how that works in practice? The front end of the site is bi lingual. I juse need the same data to show up in both languages without having to edit both languages in the panel, if that makes sense.

Im not too familiar with the mulitlang stuff in Kirby.

Well it sounds like the field will be available in all languages

If false, the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups.

Made a very simple test.

default.yml

test:
	type: structure
	translate: false
	fields:
  	head:
		type: text

default.php

<h1><?= $page->title() ?></h1>

<?php
	$tests = $page->test()->toStructure();
?>
<ul>
<?php foreach($tests as $t):?>
	<li><?= $t->head()?></li>
<?php endforeach;?>
</ul>

putting this in the template shows the content of the field in all languages.

1 Like