ez-php / i18n
Internationalisation module for the ez-php framework — file-based translations with dot-notation keys and locale fallback
1.8.0
2026-04-19 10:18 UTC
Requires
- php: ^8.5
- ez-php/contracts: ^1.0
Requires (Dev)
- ez-php/docker: ^1.0
- ez-php/testing-application: ^1.0
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.0
README
Internationalisation module for the ez-php framework — file-based translations with dot-notation keys and locale fallback.
Requirements
- PHP 8.5+
- ez-php/framework 0.*
Installation
composer require ez-php/i18n
Setup
Register the service provider:
$app->register(\EzPhp\I18n\TranslatorServiceProvider::class);
Add translation files under lang/{locale}/:
lang/
en/
messages.php → ['welcome' => 'Welcome, :name!']
de/
messages.php → ['welcome' => 'Willkommen, :name!']
Usage
$translator = $app->make(\EzPhp\I18n\Translator::class); echo $translator->get('messages.welcome', ['name' => 'Alice']); // Welcome, Alice! $translator->setLocale('de'); echo $translator->get('messages.welcome', ['name' => 'Alice']); // Willkommen, Alice!
Locale formatting
LocaleFormatter wraps PHP's ext-intl extension to format numbers, currencies, and dates in a locale-aware way:
use EzPhp\I18n\LocaleFormatter; $fmt = new LocaleFormatter('de_DE'); echo $fmt->number(1234567.89); // '1.234.567,89' echo $fmt->currency(9.99, 'EUR'); // '9,99 €' echo $fmt->date(new \DateTimeImmutable('2024-06-15')); // '15.06.2024' echo $fmt->dateTime(new \DateTimeImmutable('2024-06-15 14:30:00')); // '15.06.2024, 14:30:00'
Requires PHP's ext-intl extension.
License
MIT — Andreas Uretschnig