uran1980 / yii2-translate-panel
Yii2 Translate Panel让你的应用程序翻译变得出色!
0.1.33
2015-03-11 17:30 UTC
README
Yii2 Translate Panel让你的应用程序翻译变得出色!
本模块基于i18n (国际化) 模块,着重提高了易用性(见下面的屏幕截图)。
安装
安装Yii2
安装并配置Yii2 App Advanced 模板
Composer
通过Composer安装此扩展是首选方式。
运行以下命令之一
php composer.phar require uran1980/yii2-translate-panel "dev-master"
或者将以下内容添加到你的composer.json
文件的require部分
"uran1980/yii2-translate-panel": "dev-master"
用法
在common/config/main.php
中配置urlManager和"Yii2 Translate Panel"组件
return [ ... 'components' => [ ... 'urlManager' => [ 'class' => yii\web\UrlManager::className(), 'enablePrettyUrl' => true, 'showScriptName' => false, // false - means that index.php will not be part of the URLs ], 'i18n' => [ 'class' => uran1980\yii\modules\i18n\components\I18N::className(), 'languages' => ['en', 'de', 'fr', 'it', 'es', 'pt', 'ru'], // Or, if you manage languages in database //'languages' => function() { // /* /!\ Make sure the result is a mere list of language codes, and the // * one used in views is the first one */ // return \namespace\of\your\LanguageClass::find()->where(['active' => true'])->orderBy('default' => SORT_DESC])->select('code')->column(); //}, 'format' => 'db', 'sourcePath' => [ __DIR__ . '/../../frontend', __DIR__ . '/../../backend', __DIR__ . '/../../common', ], 'messagePath' => __DIR__ . '/../../messages', // Whether database messages are to be used instead of view ones. // Enables editing messages in locale specified by // Yii::$app->sourceLanguage // Can be set per translation category too //'forceTranslation' => true, 'translations' => [ '*' => [ 'class' => yii\i18n\DbMessageSource::className(), 'enableCaching' => true, 'cachingDuration' => 60 * 60 * 2, // cache on 2 hours // Whether database messages are to be used instead of view // ones. Enables editing messages in view code locale. // Can be set globally too. //'forceTranslation' => true, ], ], ], ... ], ... ];
在backend/config/main.php
中配置"Yii2 Translate Panel"模块
return [ ... 'modules' => [ ... 'i18n' => [ 'class' => uran1980\yii\modules\i18n\Module::className(), 'controllerMap' => [ 'default' => uran1980\yii\modules\i18n\controllers\DefaultController::className(), ], // example for set access control to module (if required): 'as access' => [ 'class' => yii\filters\AccessControl::className(), 'rules' => [ [ 'controllers' => ['i18n/default'], 'actions' => ['index', 'save', 'update', 'rescan', 'clear-cache', 'delete', 'restore', 'clear-deleted'], 'allow' => true, 'roles' => ['translator'], ] ], ], ], ... ], ... ]
运行
php yii migrate --migrationPath=@uran1980/yii/modules/i18n/migrations
访问http://backend.yourdomain.com/translations
进行消息翻译
PHP到数据库导入
如果你有一个基于PHP的旧项目,你可以通过控制台迁移到DbSource。
运行
php yii i18n/import @common/messages
其中@common/messages
是应用程序翻译的路径
数据库到PHP导出
运行
php yii i18n/export @uran1980/yii/modules/i18n/messages uran1980/modules/i18n
其中@uran1980/yii/modules/i18n/messages
是应用程序翻译的路径,uran1980/modules/i18n
是数据库中的翻译类别
使用数据库中的yii
类别
从PHP文件导入翻译
php yii i18n/import @yii/messages
信息
组件使用yii\i18n\MissingTranslationEvent自动将缺少的翻译添加到数据库