TWIG: Translation dependent on page header (frontmatter) content

Hi,

I want to improve the translations in the events plugin and have the following situation and code in files (excerpts):

languages.yaml:

en:
  PLUGIN_EVENTS:
    EVENTS:
      FREQ_NONE: none
      FREQ_DAILY: daily
      FREQ_WEEKLY: weekly
      FREQ_MONTHLY: monthly
      FREQ_YEARLY: yearly
de:
  PLUGIN_EVENTS:
    EVENTS:
      FREQ_NONE: keine Wiederholung
      FREQ_DAILY: täglich
      FREQ_WEEKLY: wöchentlich
      FREQ_MONTHLY: monatlich
      FREQ_YEARLY: jährlich

blueprints/event.yaml:

            header.event.freq:
              type: select
              label: Frequency
              help: How often should this event repeat?
              default: none
              options:
                'none': PLUGIN_EVENTS.EVENTS.FREQ_NONE
                'daily': PLUGIN_EVENTS.EVENTS.FREQ_DAILY
                'weekly': PLUGIN_EVENTS.EVENTS.FREQ_WEEKLY
                'monthly': PLUGIN_EVENTS.EVENTS.FREQ_MONTHLY
                'yearly': PLUGIN_EVENTS.EVENTS.FREQ_YEARLY

event.md:

---
uid: 'e046a6da-2179-4b53-9382-c8dbf259d46e'
title: 'test-custom'
event:
    start: '12-01-2023 15:00'
    end: '12-01-2023 16:00'
    freq: daily
    repeat: MTWRF
---

Now I want to translate the value of header.event.freq from the markdown file inside twig.
<span>{{ ("PLUGIN_EVENTS.EVENTS.FREQ_"~page.header.event.freq|upper)|t }}</span> works, but looks quite ugly in my opinion. Are there other ways to achieve this?

I use a similar approach, but with a set variable, something like

{% set event_freq = ('PLUGIN_EVENTS.EVENTS.FREQ_' ~ page.header.event.freq|upper)|t %}
...
<span>{{ event_freq|e }}</span>

with some checking if string has translation
I’m fine with it as it works) but would be interested to see other options

by the way, in your case you can use switch tag

{% switch page.header.event.freq %}
  {% case 'daily' %}
     {% set event_freq = 'PLUGIN_EVENTS.EVENTS.FREQ_DAILY'|t %}
  {% case 'weekly' %}
     {% set event_freq = 'PLUGIN_EVENTS.EVENTS.FREQ_WEEKLY'|t -%}
  {% case 'monthly' %}
     {% set event_freq = 'PLUGIN_EVENTS.EVENTS.FREQ_MONTHLY'|t -%}
  {% case 'yearly' %}
     {% set event_freq = 'PLUGIN_EVENTS.EVENTS.FREQ_YEARLY'|t -%}
  {% default %}
     {% set event_freq = 'PLUGIN_EVENTS.EVENTS.FREQ_NONE'|t %}
{% endswitch %}
...
<span>{{ event_freq|e }}</span>

@pikim, An alternative is having the blueprint write ‘PLUGIN_EVENTS.EVENTS.FREQ_DAILY’ into the frontmatter. But you might find that ugly too…

Or, in your languages.yaml, you could use FREQ_daily: daily. AFAIK, using uppercase for translation strings is just a convention, not a requirement.

Whatever alternative you use, some ugliness remains…