ez-php / i18n
Internationalisation module for the ez-php framework — file-based translations with dot-notation keys and locale fallback
Requires
- php: ^8.5
- ez-php/contracts: ^2.0
Requires (Dev)
- ez-php/docker: ^2.0
- ez-php/testing-application: ^2.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
Suggests
- ext-intl: Needed for LocaleFormatter (locale-aware number, currency and date formatting)
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.11
- 2.4.10
- 2.4.9
- 2.4.8
- 2.4.7
- 2.4.6
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.9
- 2.3.8
- 2.3.7
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.14.0
- 1.13.1
- 1.13.0
- 1.12.3
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.0
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.6
- 0.8.5
- 0.8.4
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.1
- 0.7.0
- 0.6.1
- 0.6.0
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
This package is auto-updated.
Last update: 2026-09-30 19:50:23 UTC
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!
Plurals
transChoice() accepts the simple pipe form ('no apples|one apple|:count apples', chosen by
position) or an ICU plural message, which uses the full CLDR rules of the locale when ext-intl
is installed:
// lang/pl/messages.php 'apples' => '{count, plural, one {# jabłko} few {# jabłka} many {# jabłek} other {# jabłka}}', $translator->transChoice('messages.apples', 22); // "22 jabłka" $translator->transChoice('messages.apples', 25); // "25 jabłek"
=0 {…} matches an exact count, # is the count, and :placeholders still work. Without ext-intl
only =N, one and other are used.
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