Commit f0354db1 by Alexander Makarov

Merge pull request #2177 from Ragazzo/i18n_default_category_docs

[ci skip] I18n default category docs
parents ff521fd7 a893480b
...@@ -78,7 +78,7 @@ Yii tries to load appropriate translation from one of the message sources define ...@@ -78,7 +78,7 @@ Yii tries to load appropriate translation from one of the message sources define
``` ```
In the above `app*` is a pattern that specifies which categories are handled by the message source. In this case we're 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`. handling everything that begins with `app`. You can also specify default translation, for more info see [this](specifying-default-translation) example.
`class` defines which message source is used. The following message sources are available: `class` defines which message source is used. The following message sources are available:
...@@ -287,6 +287,32 @@ extension. ...@@ -287,6 +287,32 @@ extension.
Examples Examples
-------- --------
###Specifying default translation
You can specify default translation that will be used as a fallback for categories that don't match any other translation.
This translation should be marked with `*`. In order to do it add the following to the config file (for the `yii2-basic` application it will be `web.php`):
```php
//configure i18n component
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource'
],
],
],
```
Now you can use categories without configuring each one that is similar to Yii 1.1 behavior.
Messages for the category will be loaded from a file under default translation `basePath` that is `@app/messages`:
```php
echo Yii::t('not_specified_category', 'message from unspecified category');
```
Message will be loaded from `@app/messages/<LanguageCode>/not_specified_category.php`.
###Translating module messages ###Translating module messages
If you want to translate messages for a module and avoid using a single translation file for all messages, you can make it like the following: If you want to translate messages for a module and avoid using a single translation file for all messages, you can make it like the following:
......
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