Multi-language problem with empty fields

I just encountered a weird problem and i don’t know if this is on purpose:

I have two languages activated (de / en), and german is the default language. When fill in content in to the fields of the default language and then edit the second language and delete the content of one field, the panel automatically fills this again with the content of the default language. But, it is not saved in the language text file. I can look it up via ftp.
But: in the webpage, the content from the default language field will be displayed, even though i left that field empty on purpose in the secondary language.
I find that annoying and don’t understand the reason for this behaviour. Is it a bug or a feature?
:slight_smile:

Matthias

That is indeed a feature. Kirby falls back to the default language if there is no content in the current language.

The upcoming version will have an option “isTranslated” in the blueprint, that will prevent showing the content in the Panel.

As for the fallback, Kirby 2.3 will have a method $page->myfield()->isTranslated() that will check if a field is translated and if it is not, will not display the content, see this issue on Github.

In the meantime, you can use a workaround to filter content by language.

<?php $currentLang = site()->language()->code() ?>
<?php if($page->content($currentLang)->get('yourField')->isNotEmpty()) : ?>
  // what you wanna do with your structure field
<?php endif ?>
1 Like

Super. Vielen Dank!
This works now. I didn’t know about this behaviour, but your workoaround works great around :slight_smile:

Matthias

OK so now it’s possible to use

<?php if($page->description()->isTranslated()): ?>

to check if there is a language or not, but I did not find the option being mentioned in this github issue to set in the blueprint: any update?

:slight_smile:

<?php if($page->description()->isTranslated()): ?>

does not check if there is a language, but if the value of the field is translated:

A field value is considered as translated if it is not empty and is not equal to the field value of the default language

The blueprint option you mean is translate: true/false, right? If set to false, you cannot translate the content in the Panel, i.e. the field is made read-only.

So with translate: false the field will be empty, and the isTranslated()check will return false for such a field…

2 Likes

Thank you!

No, actually what I am looking for, concerning the blueprint option, is a setting for which if the textfield is not being translated, kirby does not fill it with the default language text—but it leaves it blank.

The option you pointed out simply prevents to change that textfield to anything else when in a different language.

You mean in the panel? Or in the frontend?

Yes in the panel!

I set in the php template the isTranslated() rule, so on the website the non translated field remains blank, but in the panel I think it’s confusing to have it still showing the default language text.

I know Bastian conceived it as a feature, but there are different scenarios in which it might do the opposite.

:slight_smile:

Yes, I agree wholeheartedly. Unfortunately, I have no solution.