yiier/yii2-translate
Composer 安装命令:
composer require yiier/yii2-translate
包简介
腾讯翻译君翻译、百度翻译 、谷歌翻译(Google 翻译)
关键字:
README 文档
README
腾讯翻译君翻译,百度翻译,谷歌翻译, 彩云小译
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yiier/yii2-translate "*"
or add
"yiier/yii2-translate": "*"
to the require section of your composer.json file.
Usage
<?php $config = [ // HTTP 请求的超时时间(秒) 'timeout' => 5.0, 'from' => 'zh', // 源本语言,可选参数,默认是 zh 'to' => 'en', // 要翻译成的语言,可选参数,默认是 en // 可用的平台配置 'platforms' => [ 'qqtranslation' => [ 'app_id' => '你的 QQ AI 应用ID', 'app_key' => '你的 QQ AI 应用密钥', ], 'baidu' => [ 'app_id' => '百度翻译应用 ID', 'app_key' => '百度翻译应用秘钥', ], 'google_v2' => [ 'key' => 'xxx', // https://console.cloud.google.com/apis/credentials ], 'google_v3' => [ 'project_id' => 'xxxx', // Optional // https://github.com/googleapis/google-cloud-php/blob/master/AUTHENTICATION.md 'key_json' => '{"type":"xx","project_id":"xx","private_key_id":"xx","private_key":"","client_email":"xx","client_id":"xx","auth_uri":"xx","token_uri":"xx","auth_provider_x509_cert_url":"xx","client_x509_cert_url":"xx"}', ], 'caiyun' => [ 'token' => 'xxx', // https://fanyi.caiyunapp.com/#/api ], ], ]; $translate = new \yiier\translate\Translate($config, 'qqtranslation'); $translate->translate('今天天气怎么样'); $translate->setFrom('zh')->translate('今天天气怎么样'); $translate->setFrom('zh')->setTo('de')->translate('今天天气怎么样'); $translate->setTo('de')->translate('今天天气怎么样');
如果使用 setFrom 或者 setTo,会忽略配置文件中的配置。
⚠ 注意:如果要使用 google_v3,必须要安装官方依赖包:
composer require google/cloud-translate
PS:语言支持以 Google 的《语言支持》 为标准。
参考文档
yiier/yii2-translate 适用场景与选型建议
yiier/yii2-translate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.28k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2019 年 07 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「translate」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yiier/yii2-translate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yiier/yii2-translate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yiier/yii2-translate 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use i18n translation PHP class for multi-language websites
Store your language lines in the database, yaml or other sources
A custom URL rule class for Yii 2 which allows to create translated URL rules
An Astrotomic Translatable extension for Laravel Nova.
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
统计信息
- 总下载量: 5.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-4-Clause
- 更新时间: 2019-07-21