From 38ccc9e793d728ca777d8ef73a9600dff3bd1046 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Thu, 17 Oct 2013 15:10:00 +0400 Subject: [PATCH] Fixes #930: Added i18n docs about configuring message source --- docs/guide/i18n.md | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/docs/guide/i18n.md b/docs/guide/i18n.md index 2ec822d..0196434 100644 --- a/docs/guide/i18n.md +++ b/docs/guide/i18n.md @@ -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