To learn which inflection forms you should specify for your language you can referrer to
To learn which inflection forms you should specify for your language you can referrer to
[rules reference at unicode.org](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html).
[rules reference at unicode.org](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html).
### Selections
#### Selections
You can select phrases based on keywords. The pattern in this case specifies how to map keywords to phrases and
You can select phrases based on keywords. The pattern in this case specifies how to map keywords to phrases and
provides a default phrase.
provides a default phrase.
...
@@ -268,26 +270,7 @@ Will produce "Snoopy is dog and it loves Yii!".
...
@@ -268,26 +270,7 @@ Will produce "Snoopy is dog and it loves Yii!".
In the expression `female` and `male` are possible values. `other` handler values that do not match. Strings inside
In the expression `female` and `male` are possible values. `other` handler values that do not match. Strings inside
brackets are sub-expressions so could be just a string or a string with more placeholders.
brackets are sub-expressions so could be just a string or a string with more placeholders.
Views
### Specifying default translation
-----
You can use i18n in your views to provide support for different languages. For example, if you have view `views/site/index.php` and
you want to create special case for russian language, you create `ru-RU` folder under the view path of current controller/widget and
put there file for russian language as follows `views/site/ru-RU/index.php`.
> **Note**: If language is specified as `en-US` and there are no corresponding views, Yii will try views under `en`
> before using original ones.
Formatters
----------
In order to use formatters you need to install and enable [intl](http://www.php.net/manual/en/intro.intl.php) PHP
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.
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`):
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`):
...
@@ -313,7 +296,7 @@ echo Yii::t('not_specified_category', 'message from unspecified category');
...
@@ -313,7 +296,7 @@ echo Yii::t('not_specified_category', 'message from unspecified category');
Message will be loaded from `@app/messages/<LanguageCode>/not_specified_category.php`.
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:
...
@@ -359,7 +342,7 @@ class Module extends \yii\base\Module
...
@@ -359,7 +342,7 @@ class Module extends \yii\base\Module
In the example above we are using wildcard for matching and then filtering each category per needed file. Instead of using `fileMap` you can simply
In the example above we are using wildcard for matching and then filtering each category per needed file. Instead of using `fileMap` you can simply
use convention of category mapping to the same named file and use `Module::t('validation', 'your custom validation message')` or `Module::t('form', 'some form label')` directly.
use convention of category mapping to the same named file and use `Module::t('validation', 'your custom validation message')` or `Module::t('form', 'some form label')` directly.
###Translating widgets messages
###Translating widgets messages
Same rules can be applied for widgets too, for example:
Same rules can be applied for widgets too, for example:
...
@@ -410,4 +393,36 @@ Instead of using `fileMap` you can simply use convention of category mapping to
...
@@ -410,4 +393,36 @@ Instead of using `fileMap` you can simply use convention of category mapping to
> **Note**: For widgets you also can use i18n views, same rules as for controllers are applied to them too.
> **Note**: For widgets you also can use i18n views, same rules as for controllers are applied to them too.
TBD: provided classes overview.
Views
-----
You can use i18n in your views to provide support for different languages. For example, if you have view `views/site/index.php` and
you want to create special case for russian language, you create `ru-RU` folder under the view path of current controller/widget and
put there file for russian language as follows `views/site/ru-RU/index.php`.
> **Note**: If language is specified as `en-US` and there are no corresponding views, Yii will try views under `en`
> before using original ones.
i18n formatter
--------------
i18n formatter component is the localized version of formatter that supports formatting of date, time and numbers based
on current locale. In order to use it you need to configure formatter application component as follows:
```php
return[
// ...
'components'=>[
'formatter'=>[
'class'=>'yii\i18n\Formatter',
],
],
];
```
After cofiguring the component can be accessed as `Yii::$app->formatter`.
Note that in order to use i18n formatter you need to install and enable