Commit 38ccc9e7 by Alexander Makarov

Fixes #930: Added i18n docs about configuring message source

parent eacfe0d0
......@@ -47,9 +47,46 @@ translation of the message from source language into target language. Message it
echo \Yii::t('app', 'This is a string to translate!');
```
Yii tries to load approprite translation from one of the message sources defined via `i18n` component configuration.
Yii tries to load approprite translation from one of the message sources defined via `i18n` component configuration:
TBD: https://github.com/yiisoft/yii2/issues/930
```php
'components' => array(
// ...
'i18n' => array(
'translations' => array(
'app*' => array(
'class' => 'yii\i18n\PhpMessageSource',
//'basePath' => '@app/messages',
//'sourceLanguage' => 'en_US',
'fileMap' => array(
'app' => 'app.php',
'app/error' => 'error.php',
),
),
),
),
),
```
In the above `app*` is a pattern that specifies which categories are handled by the message source. In this case we're
handling everything that begins with `app`.
`class` defines which message source is used. There following message sources are available:
- PhpMessageSource that uses PHP files.
- GettextMessageSource that uses GNU Gettext MO or PO files.
- DbMessageSource that uses database.
`basePath` defines where to store messages for the currently used message source. In this case it's `messages` directory
in your application directory. In case of using database this option should be skipped.
`sourceLanguage` defines which language is used in `\Yii::t` second argument. If not specified, application's source
language is used.
`fileMap` specifies how message categories specified in the first argument of `\Yii::t()` are mapped to files when
`PhpMessageSource` is used. In the example we're defining two categories `app` and `app/error`.
Instead of configuring `fileMap` you can rely on convention which is `messages/BasePath/LanguageID/CategoryName.php`.
### Named placeholders
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment