switon / i18n
Per-request locale, flat translation files, fallback lookup, and optional ICU formatting for Switon Framework
v1.0.0
2026-06-06 13:43 UTC
Requires
- php: >=8.3
- switon/core: ^1.0
- switon/event: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
README
Switon's locale-aware translation layer for request-local locale state, fallback lookup, and message formatting.
Highlights
- One translation entrypoint:
TranslatorInterfacegives app services one place for message lookup. - Request-local locale: the active locale stays isolated per request.
- Fallback-aware lookup: translation files can fall back through configured candidates.
- Formatted messages: placeholders and ICU formatting both work from the same source.
- Missing-key reporting:
TranslationKeyMissingcan surface which translations are still missing.
Installation
composer require switon/i18n
Quick Start
use Switon\Core\Attribute\Autowired; use Switon\Core\LocaleInterface; use Switon\Core\TranslatorInterface; class WelcomeService { #[Autowired] protected TranslatorInterface $translator; #[Autowired] protected LocaleInterface $locale; public function message(string $name): string { $this->locale->set('en'); return $this->translator->translate('hello', ['name' => $name]); } }
Docs: https://docs.switon.dev/latest/i18n
License
MIT.