Download the PHP package gboquizosanchez/icu-i18n without Composer
On this page you can find all versions of the php package gboquizosanchez/icu-i18n. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gboquizosanchez/icu-i18n
More information about gboquizosanchez/icu-i18n
Files in gboquizosanchez/icu-i18n
Package icu-i18n
Short Description Advanced ICU Translation support for Laravel with regional fallback strategies.
License MIT
Homepage https://github.com/gboquizosanchez/icu-i18n
Informations about the package icu-i18n
Why this package?
Laravel's built-in translation support works great for simple cases — but falls short in real-world multilingual apps:
| Problem | Without this package | With icu-i18n |
|---|---|---|
| Plurals in Russian / Arabic / Polish | ❌ Impossible with :count |
✅ Native ICU MessageFormat |
App in es_MX, vendor only has es |
❌ Missing keys or wrong locale | ✅ Automatic regional fallback |
| Currency formatting by locale | ❌ Manual formatting | ✅ {amount, number, currency} |
| Localized dates | ❌ Carbon + extra setup | ✅ {date, date, long} |
| Drop-in replacement | — | ✅ Same __(), trans(), @lang |
🚀 Features
- ICU MessageFormat Support: Use standard syntax like
{count, plural, ...}or{gender, select, ...}directly in your translation files. - Smart Regional Fallback: Automatically degrades specific namespaces or files from a regional locale (e.g.,
es_MX) to a base locale (e.g.,es).- Problem Solved: You want your app to use
es_MXfor currency formatting, but your vendor packages (likelaravel/uiorspatie/permission) only publish translations ines. This package handles that automatically.
- Problem Solved: You want your app to use
- Seamless Integration: Works as a drop-in replacement for
trans(),__(), and@lang. - Native Performance: Uses PHP's native
intlextension andMessageFormatter.
📦 Installation
Publish the configuration file:
Requirements: PHP ^8.3 · ext-intl · Laravel 12 or 13
🔧 Configuration
The configuration file config/icu.php controls the Regional Fallback Strategy.
How it works
When you request a translation (e.g., __('validation.required')) while your app locale is set to Regional (e.g., es_MX), the translator decides whether to use es_MX or fall back to es based on two rules:
- Namespace Allowlist: If the translation namespace is NOT in the
namespaceslist, it falls back to the base language (es). - File Blocklist: If the translation file is in the
fileslist, it forces the base language (es), even if the namespace is allowlisted.
Default Configuration
📖 Usage
1. ICU MessageFormat
Use standard ICU syntax in your JSON or PHP translation files.
lang/en/messages.php
In your Blade views:
2. Advanced pluralization per language
ICU supports the pluralization rules of every language following the CLDR standard:
Russian — 3 plural forms
Arabic — 6 forms + dual
Polish — 4 plural forms
Slovenian — 4 forms including dual
3. Handling Object Parameters
The translator automatically converts DateTime objects to timestamps and objects implementing __toString() to strings before passing them to the ICU formatter:
🧩 Regional Fallback Examples
Assume App::setLocale('es_MX').
Scenario A: Application Strings
You have a file lang/es_MX/home.php.
- Config:
namespaces => ['*'] - Call:
__('home.title') - Result: Loads from
es_MX. (Matches*allowlist ✅)
Scenario B: Vendor Package
You use a package courier that only has translations in lang/vendor/courier/es/messages.php.
- Config:
namespaces => ['*'](does NOT includecourier) - Call:
__('courier::messages.error') - Result: Loads from
es. (Namespacecouriernot allowlisted → degrades to base locale ✅)
Scenario C: Validation Files
You want to use standard Laravel validation messages which typically exist in lang/es/validation.php, not es_MX.
- Config:
files => ['validation'] - Call:
__('validation.required') - Result: Loads from
es. (Filevalidationis blocklisted → forces base locale ✅)
ICU Syntax Reference
| Type | Syntax | Example |
|---|---|---|
| Variable | {variable} |
{name} |
| Number | {var, number} |
{count, number} |
| Currency | {var, number, currency} |
{amount, number, currency} |
| Short date | {var, date, short} |
{date, date, short} |
| Long date | {var, date, long} |
{date, date, long} |
| Plural | {var, plural, one{} other{}} |
See examples above |
| Select | {var, select, val1{} other{}} |
{gender, select, male{} female{} other{}} |
# in plural |
Replaced by the count value | {count, plural, other{# items}} |
🧪 Testing
This package uses Pest v4 with architecture and Laravel plugins. Static analysis runs via Larastan at the maximum level.
Troubleshooting
If you encounter issues:
- Check the logs — Laravel logs may contain helpful error messages.
- Verify requirements — Ensure PHP and Laravel versions meet the minimum requirements.
- Clear cache — Run
php artisan config:clearandphp artisan cache:clear. - Open an issue — Report bugs or request features.
Contributing
Contributions are welcome! Please feel free to:
- 🐛 Report bugs via GitHub Issues
- 💡 Suggest features or improvements
- 🔧 Submit pull requests with bug fixes or enhancements
- 📖 Improve documentation or add language examples
Please make sure all tests pass and the code follows the style enforced by Laravel Pint before submitting a PR.
Credits
- Author: Germán Boquizo Sánchez
- Framework: Laravel
- Standard: ICU MessageFormat
- Pluralization rules: CLDR Plural Rules
- Contributors: View all contributors
📄 License
This package is open-source software licensed under the MIT License.
All versions of icu-i18n with dependencies
ext-intl Version *
spatie/laravel-package-tools Version ^1.16
illuminate/support Version ^12.0|^13.0
illuminate/translation Version ^12.0|^13.0