Yii2 I18N module
added caching for messages and source messages, (*1)
Yii2 i18n (internalization) module makes the translation of your application so simple, (*2)
Installation
Composer
The preferred way to install this extension is through Composer., (*3)
Either run, (*4)
php composer.phar require dvixi/yii2-i18n "dev-master"
or add, (*5)
"dvixiyii2-i18n": "dev-master"
to the require section of your composer.json
, (*6)
Usage
Configure I18N component in common config:, (*7)
'i18n' => [
'class' => dvixi\yii2\I18n\components\I18N::className(),
'languages' => ['ru-RU', 'de-DE', 'it-IT']
],
Configure I18N component in backend config:, (*8)
'modules' => [
'i18n' => dvixi\yii2\I18n\Module::className()
],
Run:, (*9)
php yii migrate --migrationPath=@Zelenin/yii/modules/I18n/migrations
Go to http://backend.yourdomain.com/translations
for translating your messages, (*10)
PHP to DB import
If you have an old project with PHP-based i18n you may migrate to DbSource via console., (*11)
Run:, (*12)
php yii i18n/import @common/messages
where @common/messages
is path for app translations, (*13)
DB to PHP export
Run:, (*14)
php yii i18n/export @dvixi/yii2/I18n/messages dvixi/yii2/i18n
where @dvixi/yii2/I18n/messages
is path for app translations and zelenin/modules/i18n
is translations category in DB, (*15)
Using yii
category with DB
Import translations from PHP files, (*16)
php yii i18n/import @yii/messages
Configure I18N component:, (*17)
'i18n' => [
'class'=> dvixi\yii2\I18n\components\I18N::className(),
'languages' => ['ru-RU', 'de-DE', 'it-IT'],
'translations' => [
'yii' => [
'class' => yii\i18n\DbMessageSource::className()
]
]
],
Info
Component uses yii\i18n\MissingTranslationEvent for auto-add of missing translations to database, (*18)
See Yii2 i18n guide, (*19)
Source author
Aleksandr Zelenin, e-mail: aleksandr@zelenin.me, (*20)