Exception messages and locale

I have a problem with the correct output of exception messages in a single-language site.

My setting:
Login-protected pages. Users should also be able to change their password and e-mail address. This works fine.

locale is set in the config file:
‘locale’ => ‘de_DE.utf-8’,

If an exception is thrown when the e-mail address is changed because this e-mail address already exists, the message is in English and not in German.

However, if I test a multi-language site and create a file language/de.php, the extension-message will be in the correct language.

What can I do?

Hm, good question. One option would be to actually define that single language like you did in your test. If you set your URL to /, you will not notice the difference to a single language page, only all text files will have the language extensions.

This would work instead as well:

I18n::template($e->getKey(), null, $e->getData(), 'de');

Don’t know if there is a better way.

Turns out you could also set

Kirby\Toolkit\I18n::$locale = 'de';

in a template or controller where you want to call the Exception method.


Hi @texnixe
thank you for your quick response and your tips. Suddenly I have three working options :wink:
I will take one of the last two …