Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5636 from cakephp/3.0-optional-i18n-cache
3.0 optional i18n cache
- Loading branch information
Showing
8 changed files
with
407 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# CakePHP Internationalization Library | ||
|
||
The I18n library provides a `I18n` service locator that can be used for setting | ||
the current locale, building translation bundles and translating messages. | ||
|
||
Additionally, it provides the `Time` and `Number` classes which can be used to | ||
ouput dates, currencies and any numbers in the right format for the specified locale. | ||
|
||
## Usage | ||
|
||
Internally, the `I18n` class uses [Aura.Intl](https://github.com/auraphp/Aura.Intl). | ||
Getting familiar with it, will help you understand how to build and manipulate translation bundles | ||
should you wish to create them manually instead of using the conventions this library uses. | ||
|
||
### Setting the Current Locale | ||
|
||
```php | ||
use Cake\I18n\I18n; | ||
|
||
I18n::locale('en_US'); | ||
``` | ||
|
||
### Translating a message | ||
|
||
```php | ||
echo __( | ||
'Hi {0,string}, your balance on the {1,date} is {2,number,currency}', | ||
['Charles', '2014-01-13 11:12:00', 1354.37] | ||
); | ||
|
||
// Returns | ||
Hi Charles, your balance on the Jan 13, 2014, 11:12 AM is $ 1,354.37 | ||
``` | ||
|
||
### Creating your Own Translators | ||
|
||
```php | ||
use Cake\I18n\I18n; | ||
use Aura\Intl\Package; | ||
|
||
I18n::translator('animals', 'fr_FR', function () { | ||
$package = new Package( | ||
'default', // The formatting strategy (ICU) | ||
'default', // The fallback domain | ||
); | ||
$package->setMessages([ | ||
'Dog' => 'Chien', | ||
'Cat' => 'Chat', | ||
'Bird' => 'Oiseau' | ||
... | ||
]); | ||
|
||
return $package; | ||
}); | ||
|
||
I18n::locale('fr_FR'); | ||
__d('animals', 'Dog'); // Returns "Chien" | ||
``` | ||
|
||
### Formatting Time | ||
|
||
```php | ||
$time = Time::now(); | ||
echo $time; // shows '4/20/14, 10:10 PM' for the en-US locale | ||
``` | ||
|
||
### Formattng Numbers | ||
|
||
```php | ||
echo Number::format(100100100); | ||
``` | ||
|
||
```php | ||
echo Number::currency(123456.7890, 'EUR'); | ||
// outputs €123,456.79 | ||
``` | ||
|
||
## Documentation | ||
|
||
Please make sure you check the [official I18n | ||
documentation](http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html) | ||
|
||
The [documentation for the Time | ||
class](http://book.cakephp.org/3.0/en/core-libraries/time.html) contains | ||
instruction on how configure and output time strings for selected locales. | ||
|
||
The [documentation for the Number | ||
class](http://book.cakephp.org/3.0/en/core-libraries/number.html) shows how to | ||
use the `Number` class for displaying numbers in specific locales. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "cakephp/i18n", | ||
"description": "CakePHP Internationalization library with support for messages translation and dates and numbers localization", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "CakePHP Community", | ||
"homepage": "http://cakephp.org" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Cake\\I18n\\": "." | ||
}, | ||
"files": ["functions.php"] | ||
}, | ||
"require": { | ||
"cakephp/core": "dev-master", | ||
"ext-intl": "*", | ||
"nesbot/Carbon": "~1.13", | ||
"aura/intl": "1.1.*" | ||
}, | ||
"suggest": { | ||
"cakephp/cache": "Require this if you want automatic caching of translators" | ||
}, | ||
"minimum-stability": "dev" | ||
} |
Oops, something went wrong.