Two problems with multlanguage

Hello,
I have two questions to multilanguage site in Kirby.
Actually the language-menu is display the languagename from the config.php. But how can I translate it in the loaded language? I mean on english site should displayed “Deutsch” as “German” and on a german site should displayed “English” as “Englisch”
In the languagemenu I have an headline “language” and I want to translate this also. I wrrote an if-query but it does not work:

<?php if $site->languages()->code() === 'en' :?>
	<li>Language</li>
<?php else: ?>
	<li>Sprachen</li>
<?php endif ?>

On this I got an syntaxerror that

Parse error: syntax error, unexpected ‘$site’ (T_VARIABLE), expecting ‘(’ in /Applications/XAMPP/xamppfiles/htdocs/seven-days/site/snippets/language.php on line 2

For your code snippet, you forgot your parentheses around your condition. Try this instead:

<?php if ($site->language()->code() === 'en'): ?>
	<li>Language</li>
<?php else: ?>
	<li>Sprachen</li>
<?php endif ?>

Alternatively you could use Custom language variables instead of an if statement, simplifying your code. Follow the quick guide on the Custom language variables page. Here’s what your snippet would look like afterwards.

<li><?php echo l::get('language') ?></li>

Also personally, I would advise against using translated language names. I think it makes more sense to keep the native language names in a languages switcher.

If by chance a non-german speaker would end up on the german website, they’d have to find Englisch instead of English. In this case, it’s pretty easy to figure out, but what about languages with bigger differences between language name translations.

Here’s another example, if a german speaker ended up on a norwegian website, you’d have to find on Tysk the page to switch to german instead of Deutsch.

I don’t know if that makes sense to you. I’m not the best at explaining things.

In any case, you’d probably need to use Custom language variables for this too. So you could have for example l::set('en', 'Englisch'); in your sites/languages/de.php file.

Hope that helps!

2 Likes

I agree with @PaulMorel, I personally would also leave the language names in the language of the speakers for who that version is supposed to be.

Hi folks,
I’m agree with you, but we had here a discussion about and I was the looser :smile: .
I hope that I can change there meaning if they see in a working enviroment that this solution is not the best. I’ll see.
But thanks for it, its great to know that I’m not so wrong with my opinion.

And my parentheses mistake shows me that it is not the best to work the hole night :smile:.
And thanks for the information about the custom language variables. It is a better solution.

Greets