Download the PHP package alright/laravel-icu without Composer
On this page you can find all versions of the php package alright/laravel-icu. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alright/laravel-icu
More information about alright/laravel-icu
Files in alright/laravel-icu
Package laravel-icu
Short Description Laravel 5 package for better translation syntax using php-intl extension
License MIT
Informations about the package laravel-icu
Laravel Intl Translator
- Introduction
- Requirements
- Installation
- Publishing config and language files
- Currently adapted locales
- Publishing config and language files
- Usage examples
- Placeholders
- Select
- Plurals
- Plural offset
- Formatting in details
Introduction
Laravel ICU uses php-intl extension to provide translation for your application.
Please mind that this package breaks framework default behaviour for validators.
Due to MessageFormatter::formatMessage
method, Validator::replacer
method should return array of parameters as key-value pair, instead replacing placeholders in message.
Besides that app('translator')->get($key)
always returns message in raw format (unparsed). Translated messages are returned by:
Requirements
- Laravel 6
- php-intl extension installed
Please feel free to contribute to this package for other Laravel versions support!
Installation
If you do not have php-intl extension you can install it by following command (Ubuntu, Debian)
If you have other OS, you can use it's respective package manager
All versions
In your config/app.php
providers
Remove line
And add line:
Publishing config and language files
Be careful! This will override your existing
resources/lang/{lang}
files! Check Currently adapted locales table to see which files could be overriden.
If you would like to publish only config
If you would like to publish only one language files set
Currently adapted locales
Locale | Published files |
---|---|
en | auth.php , validation.php |
pl | auth.php , pagination.php , passwords.php , validation.php |
Usage examples
Both trans()
and trans_choice()
helper functions use this translator, so the only thing you have to change is your language files.
For detailed documentation please visit php's MessageFormatter docs and links related there
Placeholders
app/resources/lang/en/custom.php
view.blade.php
Returns
Select
app/resources/lang/en/custom.php
view.blade.php
Returns
Plurals
app/resources/lang/en/custom.php
view.blade.php
Returns
Instead of trans_choice()
you can you use trans()
helper as well.
resources/lang/en/custom.php
view.blade.php
Returns
As you can see, the only thing trans_choice()
do is passing first argument as n
parameter to trans()
helper.
Plural offset
You can set offset for your plural rules. Consider this example:
Result:
Plural rule are often very complex for languages. Intl does handle it for you.
For example in Polish few
rule is applied when n % 10 = 2..4 and n % 100 != 12..14
, while many
rule is applied when n != 1 and n % 10 = 0..1
or n % 10 = 5..9
or n % 100 = 12..14
.
In Serbian =1
will match when n = 1
, but one
will apply when n = 1, 21, 31, 41
etc.
Remember! You always have to provide
other
rule for plural translations.
For more details about pluralization please visit CLDR Plural Rules specificaton and CLDR Language plural rules.
Formatting in details
PHP's MessageFormatter also supports ordinal, spellout, number, date, time and duration formatting.
For detailed information please visit this great Yii2 Framework i18n Guide which covers every intl topic wonderfully.
All versions of laravel-icu with dependencies
illuminate/support Version ^5.3
illuminate/translation Version ^5.3
illuminate/validation Version ^5.3