Documentation · Chapter 11

Resolve locale without shared-state leaks.

LocaleResolver considers supported route, cookie, and browser-header signals in configured order, then falls back safely.

Every lesson starts from the problem, explains the mechanism, then gives a concrete verification.

Resolution order

A route prefix can be strongest, then a remembered cookie, then Accept-Language. Unsupported values fall back rather than inventing a locale.

phpaml — zsh
$translator->get('books.greeting', ['name' => $name]);
$translator->choice('books.count', $count, ['count' => $count]);

Use immutable translators

withLocale() returns a request-specific translator. Avoid mutating one shared translator in long-running or concurrent applications.

URLs and SEO

Localized pages need stable localized URLs, correct html lang, alternates when appropriate, and equivalent useful content.