metalguardian/yii2-i18n-module

此软件包已被废弃,不再维护。未建议替代软件包。

Yii2 国际化模块

安装: 184

依赖项: 0

建议者: 0

安全: 0

星标: 2

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

dev-master 2015-10-13 10:57 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:48:41 UTC


README

Yii2 国际化模块

安装

安装此扩展的首选方法是通过 composer

运行以下命令之一

php composer.phar require --prefer-dist metalguardian/yii2-i18n-module "*"

或者

"metalguardian/yii2-i18n-module": "*"

将以下内容添加到您的 composer.json 文件的 require 部分。

使用方法

如何配置组件

'components' => [
    // ...
    'i18n' => [
        'class' => '\metalguardian\i18n\components\I18n',
        // you can configure message sources, which will be used to handle all sources
        'messageSourceConfig' => [
            // here you can change all message source settings
            //'class' => \yii\i18n\DbMessageSource::className(),
        ],
        // you can turn off handling missing translations
        'handleMissing' => true,
        // here you can setup which categories to handle
        'only' => [
            'app',
            '*',
            // for example, you can add 'yii' core category
            //'yii',
        ],
        // do you want to override already configured message sources?
        'override' => true,
         // a list of languages
        'languages' => ['en', 'uk', 'fr', 'es'],
    ],
],

您可以使用这种方式处理所有消息来源

'components' => [
    // ...
    'i18n' => [
        'class' => '\metalguardian\i18n\components\I18n',
        'only' => false,
        'override' => true,
        'languages' => ['en', 'uk', 'fr', 'es'],
    ],
],

这将覆盖所有其他消息来源并设置 '*' 来源,该来源处理应用程序中的所有翻译

如果您数据库中还没有消息表,您可以使用迁移

./yii migrate --migrationPath=@vendor/metalguardian/yii2-i18n-module/src/migrations

在管理应用程序中,您需要配置翻译模块

'modules' => [
    // ...
    'i18n' => [
        'class' => 'metalguardian\i18n\Module',
    ],
],

如果您将 'i18n' 名称设置为模块,您只需调用 \metalguardian\i18n\Module::getUrl() 即可获取翻译控制器的链接

使用此模块,您可以从数据库中导出和导入翻译

从数据库中导出所有消息

./yii message/export ./common/messages

仅从数据库中导出 app 类别的消息

./yii message/export ./common/messages app

从 ./vendor/yiisoft/yii2/messages/ 中的所有文件导入翻译。脚本将询问一些问题,如导入文件的类别消息和语言

./yii message/import ./vendor/yiisoft/yii2/messages/

您可以将 override 参数添加为覆盖现有翻译与存储在文件中的翻译

./yii message/import ./vendor/yiisoft/yii2/messages/   1

或者您可以仅导入一个文件。那么您需要将所有参数作为参数指定

./yii message/import-file ./vendor/yiisoft/yii2/messages/uk/yii.php yii uk

并且如果您需要覆盖现有翻译

./yii message/import-file ./vendor/yiisoft/yii2/messages/uk/yii.php yii uk 1