core icon indicating copy to clipboard operation
core copied to clipboard

Fallback to default locale for field value does not work

Open bobvandevijver opened this issue 2 years ago • 2 comments

The translation fallback implementation currently does not work, as the isEmpty check in the doctrine behaviour dependency uses empty to determine whether the translation value is empty. It breaks as the FieldTranslation class uses an array to store its data, which contains [""] for an empty, untranslated text value.

Details

Question Answer
Relevant Bolt Version 5.0
Install type Composer install
BC Break Depending on the solution I guess
PHP version 8.0
Web server Built-in
For UX/UI issues Edge

Reproduction

Can be reproduced with the following content types (make sure to configure two locales).

homepage:
    fields:
        title:
            type: text
            localize: true
        sub_title:
            type: text
            localize: true

If you fully enter the default locale, but only a single field of the second locale, you can see the {{ record.title }} to return an empty string.

I guess this can be solved during the edit phase, to filter the empty Field translation before they are persisted into the database.

bobvandevijver avatar Oct 08 '21 08:10 bobvandevijver

Hi @bobvandevijver, thanks for the detailed issue!

Indeed that has crossed my and @bobdenotter 's minds before, but we've not been able to think of a good solution yet. One one hand, yes no value means we could show up the other locale's field value (e.g., the title in NL). But, what if the user intended for the title (or any other field) to be empty for that language?

Any suggestions here are welcome!

I-Valchev avatar Oct 25 '21 12:10 I-Valchev

Great question! I think it should be decided which use case is more likely and adapt the solution to that.

  1. The user has no translation for the field at this time (or has missed the field), and expects that the fallback locale will be used as value
  2. The user purposely left it empty because it needs to be hidden in the interface.

I believe scenario 1 is much more likely compared to scenario 2, but I have no numbers to support that whatsover. I also believe scenario 1 would be the expected behaviour when the developer has read about the fallback locale and how it works.

In terms of possible solutions: how about a checkbox with which you can indicate that the field must be translated with the value that is placed in the input? The checkbox can even be used to hide the input field when checked, but it might require a lot of clicks every time to make the fields available for input. The other way around might be better: you need to click the checkbox if you explicitly want the field to be empty. It can still hide the input, but when the checkbox is not ticked a placeholder indicating that is will fallback to the default locale (and which one that is) will further improve the UX.

Wat do you think about this?

bobvandevijver avatar Oct 28 '21 11:10 bobvandevijver