Internalization module for automatic adding of translations to database.
Based on Zelenin I18N module.
Run command
composer require vintage/yii2-i18n
or add
"vintage/yii2-i18n": "~1.1"
to the require section of your composer.json.
- Configure I18N component in common part of your application
'components' => [
'i18n' => [
'class' => vintage\i18n\components\I18N::className(),
'languages' => ['ru-RU', 'de-DE', 'it-IT'],
],
// ...
],
- Configure module in backend part of your application
'modules' => [
'i18n' => vintage\i18n\Module::className(),
// ...
],
- Applying migrations
./yii migrate --migrationPath=@vintage/i18n/migrations
Go to http://backend.your-app.dev/translations
for translating of messages.
If you have an old project with PHP-based i18n you may migrate to DbSource via console.
Run command
./yii i18n/import @common/messages
where @common/messages
is path to app translations
Run command
./yii i18n/export @vintage/i18n/messages vintage/i18n
where @vintage/i18n/messages
is path to app translations and vintage/i18n
is translations category in DB.
Import translations from PHP files
./yii i18n/import @yii/messages
Configure I18N component
'components' => [
'i18n' => [
'class'=> vintage\i18n\components\I18N::className(),
'languages' => ['ru-RU', 'de-DE', 'it-IT'],
'translations' => [
'yii' => [
'class' => yii\i18n\DbMessageSource::className()
],
],
],
],
Cache will be updates automaticly if you updates translations in dashboard.
If you using \yii\caching\FileCache
your config should be like following
// common/config/main.php
`components` => [
// ...
'i18n' => [
'class'=> vintage\i18n\components\I18N::className(),
'languages' => ['ru-RU', 'de-DE', 'it-IT'],
'enableCaching' => true,
'cache' => 'i18nCache',
],
'i18nCache' => [
'class' => \yii\caching\FileCache::className(),
'cachePath' => '@frontend/runtime/cache',
],
],
Component uses yii\i18n\MissingTranslationEvent for auto-add of missing translations to database.
Read more about I18N in official guide.
This project is released under the terms of the BSD-3-Clause license.
Copyright (c) 2017, Vintage Web Production