How to get language variables in specific language


// command
// output

Is that possible?

No, that is not supported. Theoretically, the getter supports a locale parameter, but it is not implemented. What is your use case?

I wanted to make a list with translations.

If your language variable files are in yaml format, you can get the strings like this:

$germanStrings = yaml::read(kirby()->roots()->languages() .'/de.yml');
foreach($germanStrings as $key => $value) {
  echo $key . ': ' . $value;

I just did it like this:

require($roots->languages() . DS . $code . '.php');

It worked for me.

Note that you can simple call l::get() without any parameters to get an array of all the strings. Probably more useful if you want to print a list of all strings.

I’m listing all translations of a single word (at a time).
Your approach will also be very useful.
Thank you.

If you need a translation file: read this

And i found out on the language switch that you can get the translate url page

I used:
<?php foreach ($site->languages() as $language): ?>
<li class=“menu__language-item”>
<a class=“menu__language-link” href="<?= $page->url($language->code()) ?>">
<?= html($language->code()) ?>
<?php endforeach ?>

Thank you. That’s right.