worldia / textmaster-bundle
集成 textmaster-api 的 Symfony2 扩展包
v2.2.0
2018-06-27 10:39 UTC
Requires
- php: >=7.0
- doctrine/doctrine-bundle: ^1.5
- doctrine/orm: ^2.5
- symfony/form: ^3.2|^4.0
- symfony/framework-bundle: ^3.2|^4.0
- symfony/property-access: ^3.2|^4.0
- symfony/security-csrf: ^3.2|^4.0
- symfony/validator: ^3.2|^4.0
- worldia/textmaster-api: ^1.0
Requires (Dev)
- behat/symfony2-extension: 2.1.*
- matthiasnoback/symfony-config-test: ^3.0
- matthiasnoback/symfony-dependency-injection-test: ^2.0
- phpunit/phpunit: ^6.0
- symfony/asset: ^3.2|^4.0
- symfony/browser-kit: ^3.2|^4.0
- symfony/templating: ^3.2|^4.0
- symfony/twig-bundle: ^3.2|^4.0
- white-october/pagerfanta-bundle: ^1.0
Suggests
- white-october/pagerfanta-bundle: Needed to display pager on list template if you add routing.
README
这是一个集成 textmaster-api 的 Symfony2 扩展包。
安装
步骤 1: 使用 composer 下载 TextmasterBundle
使用 composer 需求扩展包
$ composer require worldia/textmaster-bundle
步骤 2: 启用扩展包
在内核中启用扩展包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Worldia\Bundle\TextmasterBundle\WorldiaTextmasterBundle(), // ... ); }
步骤 3: 配置扩展包
// in app/config/config.yml worldia_textmaster: credentials: api_key: your_api_key api_secret: your_api_secret
步骤 4: 添加路由
翻译管理器使用回调路由。
// in app/config/routing.yml worldia_textmaster_callback: resource: @WorldiaTextmasterBundle/Resources/config/routing/callback.yml
附加安装
配置
默认情况下,使用的翻译提供者是 ArrayBasedMappingProvider。您可以轻松地进行以下配置
// in app/config/config.yml worldia_textmaster: mapping_properties: AppBundle\Entity\FirstEntity: ['property1', 'property2', 'property3', ...] AppBundle\Entity\SecondEntity: ['propertyA', 'propertyB', 'propertyC', ...] ...
为每个路由提供了一个模板。您可以通过配置轻松覆盖它
// in app/config/config.yml worldia_textmaster: templates: project: show: 'MyTemplate:Project:show.html.twig' list: 'MyTemplate:Project:list.html.twig'
路由
您可以选择添加对象路由文件。
如果您这样做,则需要 white-october/pagerfanta-bundle 来在列表页显示分页器。
// in app/config/routing.yml worldia_textmaster_project: resource: @WorldiaTextmasterBundle/Resources/config/routing/project.yml worldia_textmaster_document: resource: @WorldiaTextmasterBundle/Resources/config/routing/document.yml worldia_textmaster_job: resource: @WorldiaTextmasterBundle/Resources/config/routing/job.yml
使用示例
创建带有文档的项目
<?php // src/AppBundle/MyService/MyService.php namespace AppBundle\MyService; use Worldia\Bundle\TextmasterBundle\Translation\TranslationManager; class MyService { /** * @var TranslationManager */ protected $translationManager; public function createProject() { // retrieve all entities to translate in array $translatable. $project = $this->translationManager->create( $translatable, 'Project name', 'en', 'fr', 'CO21', 'My poject briefing', array('language_level' => 'premium') ); // the project is sent to TextMaster and launched. } }
API 回调
该扩展包提供了一个带有路由的控制器,用于捕获 API 回调。
这将调用 textmaster-api 处理器,根据其实体状态引发相应的事件。
然后,一个监听器(DocumentListener 或 ProjectListener)将捕获此事件并相应处理。
例如,'textmaster.document.in_review' 事件将获取与文档相关的作业并完成它。