getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.32k stars 168 forks source link

[3.8.0-rc.2] Blueprint option with translated labels not working #4726

Closed doup closed 2 years ago

doup commented 2 years ago

Description

Blueprint field select with translated label options is not working anymore. This was working in 3.7.0.

Expected behavior

It should show the label.

Screenshots

image

image

To reproduce

I'm using the following blueprint config:

    fields:
      type:
        type: select
        translate: false
        label:
          eu: Ekitaldi mota
          es: Tipo de evento
        width: 1/3
        default: single
        required: true
        options:
          single:
            eu: Egun bakarrekoa
            es: Día único
          multiple:
            eu: Egun anitzekoa
            es: Multiples dias

Your setup

Kirby Version: 3.8.0-rc.2

distantnative commented 2 years ago

@doup Could you try the following and let me know if this solves your problem?

public function render(ModelWithContent $model): string|null
{
    if ($text = I18n::translate($this->translations)) {
        return $text;
    }

    if (isset($this->translations['*']) === true) {
        return I18n::translate($this->translations['*'], $this->translations['*']);
    }

    return $this->translations['en'] ?? null;
}
doup commented 2 years ago

@distantnative nope, that doesn't do the trick.

doup commented 2 years ago

Just in case I've tried changing my panel user language from English to Español (Spanish), but that didn't change anything. Also, I've double checked in 3.7.0 and it was indeed working:

image

image

distantnative commented 2 years ago

Ok what I can still reproduce is that there is no fallback when your current language is not any of the languages specified in the blueprint and there is no English one present either.

But if the current language is actually one of the ones specified in the blueprint, it works for me.

Are you sure your user language (Your Account) is set to either eu or es? The label translations are based on the Panel user language, not the currently selected content translation language.

distantnative commented 2 years ago

Another try for the "missing EN, instead fall back to first defined language" bug:

public function render(ModelWithContent $model): string|null
{
    if ($text = I18n::translate($this->translations)) {
        return $text;
    }

    if (isset($this->translations['*']) === true) {
        $key = $this->translations['*'];
        return I18n::translate($key, $key);
    }

    if (isset($this->translations['en']) === true) {
        return $this->translations['en'];
    }

    return array_values($this->translations)[0] ?? null;
}
afbora commented 2 years ago

@distantnative In 3.7.5 works sample blueprint and shows first translation as fallback. But in 3.8 doesn't work.

Another try for the "missing EN, instead fall back to first defined language" bug:

This worked for me.

distantnative commented 2 years ago

With https://github.com/getkirby/kirby/pull/4728 I would think that it restores same functionality as 3.7.5 for fallbacks.

doup commented 2 years ago

The latest snippet works for me. I know the Panel language is based on the user language and not the content one. In my case I've the panel user in English… because I just prefer it; but my client will probably use either Spanish or Basque.

Kirby can't assume that the user language will match with the label translations (otherwise it should constraint the user language selection to the ones used in blueprint labels).

distantnative commented 2 years ago

No exactly it shouldn't be restricted. But then you were really affected by the last edge case where the user language was not specified. That'll be fixed.

bastianallgeier commented 2 years ago

Can we close this after the PR has been merged?

distantnative commented 2 years ago

I would think so, yes.