How to get the information if a page has a translation file as .txt in content folder?

Hi,

Short Description: I have a multi-language setup (de, en). Right now, Kirby gives default content of de back if no translation .txt-file in en is available.

Long Description:
I was reading these old posts and also documentation to solve it on my own first

I have a solution with that piece of code: $page->content($kirby->language('en')->code())->get('text')->toBlocks()->isEmpty() It works good if a .txt in en is available with a field text:.
With the return value of isEmpty() in an If-statement, I can handle a redirect to 404-page with go('error') if no translation is existing.

I was wondering if there is a better way to do that with $ContentTranslation or another way? Because if no translation txt-file is given, then default language de is placed and no redirect to 404-page is happening. That means the English site is placing german content. That’s shouldn’t be like that. It could provoke a logic error provoked by human… :sweat_smile:

Here are some code of experiment with $contentTranslation: But I can’t get a value back…

echo("ContentTranslation: ");
echo($page->contenttranslation()->exists());
echo($page->contenttranslation()->isDefault());
echo($page->contenttranslation()->content());
echo($page->contenttranslation()->id());

best regards
ET

You can check if a translation exists with

$page->translation(kirby()->language()->code())->exists();
1 Like

Works pretty good!