vintage/yii2-i18n

数据库自动添加翻译的内部化模块

1.3.0 2017-08-30 06:57 UTC

This package is not auto-updated.

Last update: 2024-09-15 01:50:56 UTC


README

Yii2的内部化模块


自动将翻译添加到数据库的内部化模块。

基于Zelenin I18N模块。

Total Downloads Latest Stable Version Latest Unstable Version

安装

安装包

运行命令

composer require vintage/yii2-i18n

或添加

"vintage/yii2-i18n": "~1.1"

到您的composer.json的require部分。

配置

  1. 在应用程序的公共部分配置I18N组件
'components' => [
    'i18n' => [
        'class' => vintage\i18n\components\I18N::className(),
        'languages' => ['ru-RU', 'de-DE', 'it-IT'],
    ],
    // ...
],
  1. 在应用程序的后端部分配置模块
'modules' => [
	'i18n' => vintage\i18n\Module::className(),
	// ...
],
  1. 应用迁移
./yii migrate --migrationPath=@vintage/i18n/migrations

使用方法

转到http://backend.your-app.dev/translations进行消息翻译。

PHP到数据库导入

如果您有一个基于PHP的i18n的旧项目,您可以通过控制台迁移到DbSource。

运行命令

./yii i18n/import @common/messages

其中@common/messages是应用程序翻译的路径

数据库到PHP导出

运行命令

./yii i18n/export @vintage/i18n/messages vintage/i18n

其中@vintage/i18n/messages是应用程序翻译的路径,而vintage/i18n是数据库中的翻译类别。

使用数据库的yii类别

从PHP文件导入翻译

./yii i18n/import @yii/messages

配置I18N组件

'components' => [
    'i18n' => [
        'class'=> vintage\i18n\components\I18N::className(),
        'languages' => ['ru-RU', 'de-DE', 'it-IT'],
        'translations' => [
            'yii' => [
                'class' => yii\i18n\DbMessageSource::className()
            ],
        ],
    ],
],

缓存

如果您在仪表板上更新翻译,缓存将自动更新。

如果您使用\yii\caching\FileCache,则您的配置应如下所示

// 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',
    ],
],

其他

组件使用yii\i18n\MissingTranslationEvent自动将缺失的翻译添加到数据库。

有关I18N的更多信息,请参阅官方指南

许可证

License

本项目根据BSD-3-Clause许可证发布。

版权(c) 2017, Vintage Web Production