worldia/textmaster-bundle

集成 textmaster-api 的 Symfony2 扩展包

安装量: 15,894

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 10

分支: 0

开放问题: 0

类型:symfony-bundle

v2.2.0 2018-06-27 10:39 UTC

README

Build Status Scrutinizer Code Quality Code Coverage

这是一个集成 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' 事件将获取与文档相关的作业并完成它。