Is there a smart way to use translated strings in select boxes in the panel?

Hi,

Anybody here knows a smart way to use translations in select fields? I’ve worked with API’s for this but feels like much overhead for something that simple.

So I want for example:

myselect:
  type: select
  label: string.translation.myselect
  options:
    option1: string.translation.option1
    option2: string.translation.option2

Cheers!

Now: Programmable blueprints | Kirby CMS
Future: Support i18n keys for form options by distantnative · Pull Request #3959 · getkirby/kirby · GitHub

Just saw the link on discord from you, this helped a lot!

This is how I solved it for now (I needed the array walk because using translate on plugin runtime apparently wasn’t a good idea, didn’t work at least.

<?php

use Kirby\Toolkit\I18n;

$options = kirby()->option('myplugin.core.sizes');

array_walk($options, function(&$val, $key) {
    $val = I18n::translate($val);
});

return [
    'label' => I18n::translate('fields.common.layout.size.label'),
    'options' => $options,
    'type' => 'select',
];

Still feels a little bit bonkers though. :sweat_smile:

Cheers!