nercury / translation-editor-bundle
Translation editor form. Defines a form type to edit localized object translations.
Installs: 2 712
Dependents: 6
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 3
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.2
- doctrine/orm: >=2.1.0
- symfony/symfony: >=2.3
This package is not auto-updated.
Last update: 2024-12-21 15:03:32 UTC
README
It is a translation editor form.
Using it with array
Example data:
$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":
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").
$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:
| product | | product_translation |
| id | ------ | product_id |
| lang |
| name (localised) |
It follows the same style the old Doctrine1 behaviours used to do it.
Main Product entity must have a doctrine collection of translations, and "getTranslations()" method, and you should build your form using its name.
It will find other stuff in Doctrine class metadata.
Form theme
You can override form theme by overriding "fields.html.twig" file.
Javascript
@NercuryTranslationEditorBundle/Resources/public/js/translations_form.js
Example
Example doctrine entity:
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; }