If no translations -> redirect to home page

Hi I would like to create some template redirector if page don’t have translations

Im try to use this code but it isn’t help me, what im doing wrong…

<?php if($page->layout()->translations(kirby()->language()->code())->exists()): ?>
<?php snippet('header') ?>
<main id="main">
	
<?php foreach ($page->layout()->toLayouts() as $layout): ?>
...
<?php endforeach ?>	

</main>
<?php snippet('footer') ?>
<?php else: ?>
<?php Header::redirect($site->url()); ?>
<?php endif ?>

A field object doesn’t have a translations() or translation() method. What exactly do you want to check? If the content file in a given language doesn’t exist? If the content in general is empty? Or really depending just on the layouts field?

I wish to check if field “layout” have translation (have any data in non main language file)

if I check just it like this
<?php if($page->layout()->exists()): ?>
or
<?php if($page->layout()->isNotEmpty()): ?>
the page is loading I think this is because of main file

If I use this for some simple field (like text) it’s works. But for Layout it is not work… so that is why i’m try to find solution via checking translations… by the way this is works for builder field too, but not for layout…

Oh, I think I found the way
<?php if($page->layout()->toLayouts()->isNotEmpty()): ?>