Localization
The renderer provides the current locale, translations and localized URL generation. The language switcher is a regular server-rendered link.
Configuring locales
Localization.yaml sets both default_locale and fallback_locale to cs and lists cs/en in supported_locales. url.enabled turns on localized URLs. Config.yaml must include the Localization module for this file to load.
module: localization
config:
default_locale: cs
fallback_locale: cs
supported_locales: [cs, en]
url:
enabled: trueTranslation catalogs
app/Language/en/messages.php returns the English messages group. The filename supplies the group name, so welcome is read as messages.welcome. Put the Czech counterpart in app/Language/cs/messages.php.
<?php
declare(strict_types=1);
return [
'welcome' => 'Welcome to Lemonade.',
'navigation.home' => 'Home',
];Translations and localized URLs
Routing registers the named home route inside localizedGroup() so a locale-aware URL can be generated. In the view, lang() reads the active translation, localizedUrl() builds the link, and e() escapes both for HTML. Outside views, use TranslatorInterface::get().
<?php
declare(strict_types=1);
$router->localizedGroup(static function (Router $router): void {
$router->getNamed(
'home',
'/',
ControllerAction::for(HomeController::class, 'index'),
);
});
?>
<!-- In a request-rendered view: -->
<h1><?= e($this->lang('messages.welcome')) ?></h1>
<a href="<?= e($this->localizedUrl('home')) ?>">Home</a>