2017 © Pedro PelĂĄez
 

symfony-bundle translation-editor-bundle

Translation editor form. Defines a form type to edit localized object translations.

image

nercury/translation-editor-bundle

Translation editor form. Defines a form type to edit localized object translations.

  • Monday, November 23, 2015
  • by Tadcka
  • Repository
  • 4 Watchers
  • 1 Stars
  • 1,790 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

What it is

It is a translation editor form., (*1)

Translation editor example, (*2)

Using it with array

Example data:, (*3)

$data = array(
    'translations' => array(
        array(
            'lang' => 'lt',
            'name' => 'Produktas',
            'description' => 'Produkto apraĆĄymas'
        ),
        array(
            'lang' => 'en',
            'name' => 'Product',
            'description' => 'Product description',
        ),
    ),
);

Form requires that you create a form type for inner item, in this case it is named "TestType":, (*4)

class TestType extends \Symfony\Component\Form\AbstractType
{
    public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
    {
        $builder->add('name');
        $builder->add('description');
    }

    public function getName()
    {
        return 'translation_item_form';
    }
}

Form type is implemented in similar fassion as a collection. Use "type" to specify inner type form. Use "locale_field_name" to override locale field name (default is "lang")., (*5)

$formBuilder = $this->createFormBuilder($data);
$formBuilder->add('translations', 'translations', array(
    'type' => new TestType(),
    'locale_field_name' => '[lang]',
    'locales' => array('lt', 'en', 'ru'),
));

Using it with a collection and entities

Form type also works with database translations defined in this or smilar table structure:, (*6)


| product | | product_translation | | id | ------ | product_id | | lang | | name (localised) |

It follows the same style the old Doctrine1 behaviours used to do it., (*7)

Main Product entity must have a doctrine collection of translations, and "getTranslations()" method, and you should build your form using its name., (*8)

It will find other stuff in Doctrine class metadata., (*9)

Form theme

You can override form theme by overriding "fields.html.twig" file., (*10)

Javascript

@NercuryTranslationEditorBundle/Resources/public/js/translations_form.js

Example

Example doctrine entity:, (*11)

namespace Example\AcmeBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="acme")
 */
class Acme
{
    /**
     * @var \Doctrine\Common\Collections\ArrayCollection|AcmeTranslation[]
     *
     * @ORM\OneToMany(
     *      targetEntity="Example\AcmeBundle\Entity\AcmeTranslation", 
     *      mappedBy="acme", 
     *      cascade={"persist", "remove"}
     * )
     */
    private $translations;
}

namespace Example\AcmeBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="acme_translations")
 */
class AcmeTranslation
{
    /**
     * @var Acme $acme
     *
     * @ORM\ManyToOne(targetEntity="Example\AcmeBundle\Entity\Acme", inversedBy="translations")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(
     *       name="acme_id", 
     *       referencedColumnName="id", 
     *       onDelete="CASCADE", 
     *       nullable=false
     *   )
     * })
     */
    private $acme;

    /**
     * @var string $lang
     *
     * @ORM\Column(name="lang", type="string", length=31, nullable=false)
     */
    private $lang;

    /**
     * @var string $title
     *
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
     */
    private $title;

    /**
     * @var string $description
     *
     * @ORM\Column(name="description", type="text", nullable=true)
     */
    private $description;
}

The Versions

23/11 2015

0.1.x-dev

0.1.9999999.9999999-dev https://github.com/Nercury/TranslationEditorBundle

Translation editor form. Defines a form type to edit localized object translations.

  Sources   Download

Apache

The Requires

 

by Nerijus Arlauskas

translations translation locales

23/11 2015

v0.1.4

0.1.4.0 https://github.com/Nercury/TranslationEditorBundle

Translation editor form. Defines a form type to edit localized object translations.

  Sources   Download

Apache

The Requires

 

by Nerijus Arlauskas

translations translation locales

21/10 2014

dev-master

9999999-dev https://github.com/Nercury/TranslationEditorBundle

Translation editor form. Defines a form type to edit localized object translations.

  Sources   Download

Apache

The Requires

 

by Nerijus Arlauskas

translations translation locales

13/03 2014

v0.1.3

0.1.3.0 https://github.com/Nercury/TranslationEditorBundle

Translation editor form. Defines a form type to edit localized object translations.

  Sources   Download

Apache

The Requires

 

by Nerijus Arlauskas

translations translation locales

27/02 2014

v0.1.2

0.1.2.0 https://github.com/Nercury/TranslationEditorBundle

Translation editor form. Defines a form type to edit localized object translations.

  Sources   Download

Apache

The Requires

 

by Nerijus Arlauskas

translations translation locales

31/01 2014

v0.1.1

0.1.1.0 https://github.com/Nercury/TranslationEditorBundle

Translation editor form. Defines a form type to edit localized object translations.

  Sources   Download

Apache

The Requires

 

by Nerijus Arlauskas

translations translation locales