Show translated blueprint options on final site?

I’m creating a multilanguage site (my first kirby site btw) and it works quite well, but the translated “options” from my blueprint do not get translated on the website itself.

My blueprint looks like this

options:
  monday: 
    en: monday
    fr: lundi
  tuesday: 
    en: tuesday
    fr: mardi

I already understood that they only appear when a panel user uses the specific language. But how can I access the translation on the site or solve my problem otherwise?

Thanks!

Hey @luap,

Welcome to the Kirby forum.

The translated labels are only displayed in the Panel, they are not stored in your content files (only the value is, in this case monday and tuesday.

There are at least two ways to get the translations into the frontend:

The first option requires you to define these translations manually again.
If you use the second option, Kirby has to read the blueprints, so this might be a bit slower.

Hey @texnixe, thanks for the quick reply before the weekend!
I am not only new to kirby but also to php, to be honest.

Your first proposal looks good, translating seven “days” is no problem. But I couldn’t figure out where to put my “day” variable there (for the seven days of the week…). My guess is, it’s not possible…
This is my code right now

<?= $event->day()->kirbytext() ?>

With the second solution I wouldn’t even know where to start!

Thanks!

For the first option, you would define the variables in your language files:

return [
  'code'         => 'fr',
  'default'      => false,
  'direction'    => 'ltr',
  'locale'       => 'fr_Fr',
  'name'         => 'Français',
  'translations' => [
    'monday'    => 'lundi',
    'tuesday'   => 'mardi',
    'wednesday' => 'mercredi'
  ]
];

Then in your template, you use the t() helper function to get the translation for the string stored in your day field:

<?= t($event->day()->value()) ?>

So if the value of the day field was tuesday and the user is on the French version of the site, it would render mardi.

Edit: You have to set the translations in each language file, including the default language.

Thank you! That worked! I had missed the ->value before. But I still had to “translate” the days in my english default language file.

Yes, you have to do that for every language. Sorry for being unclear.

No Problem, since you mentioned it in another question I had read before.

A post was merged into an existing topic: Kirby Tags multilanguage