Chapter 13 of 15

Localization.

Store translations in file catalogs and resolve the locale primarily from the URL.

Translation catalogs

Catalogs live in app/Language/{locale}/{group}.php. TranslatorInterface::get() and $this->lang() in views read group.key entries.

app/Language/en/messages.php
<?php

declare(strict_types=1);

return [
    'welcome' => 'Welcome to Lemonade.',
    'navigation.home' => 'Home',
];

Set default, fallback, and supported locales in Localization.yaml. Missing translations are looked up in the fallback locale.

Localized URLs

localizedGroup() adds a localized route group variant. Generate links in views with $this->localizedUrl(); use an explicit application map when URL segments differ by language.

Localized routes and links
<?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>

The application takes the locale from the URL parameter and applies it through TranslatorInterface::setLocale() at the start of the request. The request renderer then exposes the same value through $this->currentLocale().

Detailed technical documentation on GitHub