A Symfony2 bundle integrating textmaster-api.
Require the bundle with composer:
$ composer require worldia/textmaster-bundle
Enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Worldia\Bundle\TextmasterBundle\WorldiaTextmasterBundle(),
// ...
);
}
// in app/config/config.yml
worldia_textmaster:
credentials:
api_key: your_api_key
api_secret: your_api_secret
The translation manager is using the callback routes.
// in app/config/routing.yml
worldia_textmaster_callback:
resource: @WorldiaTextmasterBundle/Resources/config/routing/callback.yml
By default, the translator provider used is the ArrayBasedMappingProvider. You can easily configure it as followed:
// in app/config/config.yml
worldia_textmaster:
mapping_properties:
AppBundle\Entity\FirstEntity: ['property1', 'property2', 'property3', ...]
AppBundle\Entity\SecondEntity: ['propertyA', 'propertyB', 'propertyC', ...]
...
There is a template provided for each route. You can override it easily with configuration:
// in app/config/config.yml
worldia_textmaster:
templates:
project:
show: 'MyTemplate:Project:show.html.twig'
list: 'MyTemplate:Project:list.html.twig'
You can optionally add object routing files.
If you do you will need white-october/pagerfanta-bundle to display pager on list page.
// 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
Create a project with documents:
<?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.
}
}
The bundle provide a controller with a route to catch API callback.
This will call textmaster-api Handler to raise en event corresponding to the right object depending on its status.
Then a listener (DocumentListener or ProjectListener) will catch this event and act accordingly.
For example, an event for 'textmaster.document.in_review' will get the job related to the document and finish it.