Commit cbd55412 by Mark

docs about default translation added

parent 5cab2a87
......@@ -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
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:
......@@ -287,6 +287,43 @@ extension.
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 `*`. For example do this in your config file (for the `yii2-basic` application it will be `web.php`):
```php
//configure i18n component
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource'
],
],
],
```
After that you can start using your categories without specifying them in i18n translations. This is more familiar as for Yii1. Now you can create
files under default category `basePath` and simply use them as usual, for example:
1. create your category file under messages `basePath`, according default translation. Since we are not overriding `basePath` property of
[`PhpMessageSource`](https://github.com/yiisoft/yii2/blob/master/framework/i18n/PhpMessageSource.php#L40) it would be `@app/messages`.
```php
# not_specified_category.php file under @app/messages directory.
return [
'message from not specified category' => 'сообщение из не указанной категории',
];
```
2. Use your category as before.
```php
echo Yii::t('not_specified_category','message from not specified category');
```
###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:
......
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