wbtranslator / yii2-wbt
WBTranslator 的 Yii 插件
v0.1.0
2017-10-19 11:23 UTC
Requires
- php: ^7
- wbtranslator/wbt-sdk-php: ^0.1
This package is not auto-updated.
Last update: 2024-09-29 02:13:34 UTC
README
使用 composer 安装
composer require wbtranslator/yii2-wbt
设置插件配置
如果您使用的是基本版本,请将默认语言设置在 console.php 中。
$config = [
...
'language' => 'ru',
...
];
如果您使用的是高级模板,请将默认语言设置在 common/main.php 或 console/main.php 中。
在控制台应用程序的引导配置中添加 wbt_plugin
$config = [
...
'bootstrap' => ['log', 'wbt_plugin'],
...
];
在相同的配置文件中添加插件的配置,$config 数组。
'modules' => [
...
'wbt_plugin' => [
'class' => wbtranslator\wbt\WbtPlugin::class,
'langMap' => [
'PhpMessageSource' => [
'basic' => '@app/messages',
]
],
'apiKey' => 'your_project_api_key'
],
...
],
在配置选项 langMap 中,您可以自定义翻译存储。
在 basic 部分 PhpMessageSource 配置选项中,您必须写下您项目的名称。
如果您使用的是高级模板,并且您有多个包含翻译的默认存储,您可以将其全部添加到 PhpMessageSource 配置选项中。
'modules' => [
...
'wbt_plugin' => [
'class' => wbtranslator\wbt\WbtPlugin::class,
'langMap' => [
'PhpMessageSource' => [
'common' => '@common/messages',
'common' => '@common/my-messages',
'frontend' => '@frontend/messages',
'backend' => '@backend/messages',
'console' => '@console/messages',
]
],
'apiKey' => 'your_project_api_key'
],
...
],
在插件选项 PhpMessageSource 键中 - 是您应用程序和应用文件夹的名称,值 - 是此应用程序中翻译文件夹的路径。
您还可以从数据库中提取您的翻译。
'modules' => [
...
'wbt_plugin' => [
'class' => wbtranslator\wbt\WbtPlugin::class,
'langMap' => [
'DbMessageSource' => [
'messageTable' => 'message',
'sourceMessageTable' => 'source_message'
],
],
'apiKey' => 'your_project_api_key'
],
...
],
在选项 messageTable、sourceMessageTable 中,您可以填写您自定义的翻译表。
'wbt_plugin' => [
...
'apiKey' => 'your_project_api_key'
...
],
apiKey 是必需的选项,您可以在项目的 API 部分找到它。
###将包含翻译的文件夹权限设置为服务器可写
$ chmod -R 775 ./resources/lang/
使用网页界面
从控制台命令发送抽象到 WBTranslator
php yii wbt_plugin/wbt/export
从 WBTranslator 获取抽象并将其保存到语言目录中
php yii wbt_plugin/wbt/import