I’m trying to get translatable options in a select field and I’m trying to do it without building a new custom field plugin I’m stuck atm, maybe somebody else has any creative ideas
My blueprint is a basic selectbox and I want it to have configurable options. (and translated)
First attempt: Just putting the translations in the option field and hoping that the array gets automagically converted to the right blueprint syntax. (failed, I guess this is not the feature I am looking for )
buttonType:
width: 1/2
label:
en: Button type
nl: Knop type
type: select
options: query
query: kirby.options('buttons')
<?php
return [
'buttons' => [
'default' => [
'nl' => 'Standaard',
'en' => 'Default',
]
]
];
Second attempt: Trying to use an api to use the active user language and fetch the right options. Failed because I can’t access the language on runtime. Third attempt putting the routes in the ready one but also failed because (obviously) routes need to be loaded on runtime.
buttonType:
width: 1/2
label:
en: Button type
nl: Knop type
type: select
options: api
api: "{{ site.url }}/components/common/links/button.json"
<?php
return [
'buttons' => [
'nl' => [
'default' => 'Standaard',
],
'en' => [
'default' => 'Default',
],
],
'ready' => function($kirby) {
return [
'routes' => [
[
'pattern' => 'components/common/links/button.json',
'action' => function () {
return option('buttons.'. kirby()->user()->language());
}
]
],
];
}
];
So I’m out of good ideas. Any other good or creative ideas out there to make this happen?