2017 © Pedro Peláez
 

symfony-bundle textmaster-bundle

A Symfony2 bundle integrating textmaster-api

image

worldia/textmaster-bundle

A Symfony2 bundle integrating textmaster-api

  • Wednesday, June 27, 2018
  • by cdaguerre
  • Repository
  • 8 Watchers
  • 0 Stars
  • 13,805 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 27 Versions
  • 6 % Grown

The README.md

TextmasterBundle

Build Status Scrutinizer Code Quality Code Coverage, (*1)

A Symfony2 bundle integrating textmaster-api., (*2)

Installation

Step 1: Download TextmasterBundle using composer

Require the bundle with composer:, (*3)

$ composer require worldia/textmaster-bundle

Step 2: Enable the bundle

Enable the bundle in the kernel:, (*4)

<?php
    // app/AppKernel.php

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Worldia\Bundle\TextmasterBundle\WorldiaTextmasterBundle(),
            // ...
        );
    }

Step 3: Configure the bundle

// in app/config/config.yml

worldia_textmaster:
    credentials:
        api_key: your_api_key
        api_secret: your_api_secret

Step 4: Add route

The translation manager is using the callback routes., (*5)

// in app/config/routing.yml

worldia_textmaster_callback:
    resource: @WorldiaTextmasterBundle/Resources/config/routing/callback.yml

Additional installation

Configuration

By default, the translator provider used is the ArrayBasedMappingProvider. You can easily configure it as followed:, (*6)

// 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:, (*7)

// in app/config/config.yml

worldia_textmaster:
    templates:
        project:
            show: 'MyTemplate:Project:show.html.twig'
            list: 'MyTemplate:Project:list.html.twig'

Route

You can optionally add object routing files.
If you do you will need white-october/pagerfanta-bundle to display pager on list page., (*8)

// 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

Usage example

Create a project with documents:, (*9)

<?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 callback

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., (*10)

The Versions