How to translate options in select field?

@mnemotechnikon I think I should update my answers given…

Continuing on the initial post using the method 'hagne::kittenStatus()' I proposed a solution for translations in PHP in posts #2 and #4.

However, using these translations in PHP, the select field displays the translation belonging to the language being selected for the current page being edited in Admin panel.

On second thought, I think it is more logical to have the select contain the translations for the language of the user (Administrator/Editor) of the Admin panel.
In other words, if the language of the user of the Admin panel is set to Polish, the select should always display the Polish translation independent of the language being selected for the current page.

This can easily be achieved by using the following field definition in '/blueprints/default.yaml':

header.status:
    type: select
    label: KITTENSTATUS
    options:
      'STATUS.SOLD': 'STATUS.SOLD'
      'STATUS.RESERVED': 'STATUS.RESERVED'
      'STATUS.AVAILABLE': 'STATUS.AVAILABLE'

To show the translation in the front-end, use the following in template ‘default.html.twig’ (or any other):

<p>Status: {{page.header.status|t}}</p>

The method 'hagne::kittenStatus()' has therefor become obsolete.

1 Like