2017 © Pedro Peláez
 

symfony-bundle doctrine-util-bundle

Simple way to translate your entities in forms

image

tuxes3/doctrine-util-bundle

Simple way to translate your entities in forms

  • Thursday, August 28, 2014
  • by Tuxes3
  • Repository
  • 2 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

DoctrineUtilBundle

Simple way to translate your entities in forms., (*1)

Installation: add to you composer.json https://packagist.org/packages/tuxes3/doctrine-util-bundle, (*2)

Add to your project in your AppKernel.php:, (*3)

...
new TX3\DoctrineUtilBundle\Tuxes3DoctrineUtilBundle(),
...

Annotated your entities, (*4)

...
use TX3\DoctrineUtilBundle\Annotations as TX3;
...
/**
 * @var string
 * @TX3\Translatable()
 */
protected $name;

/**
 * @TX3\Translatable(true)
 */
protected $translations = array();
...

Use it in a FormType, (*5)

...
$builder->add('translations', 'translation', array(
    'label' => 'Tag Name',
));
...

A form is rendered with an input for each defined languag in config.yml:, (*6)

tuxes3_doctrine_util:
    locales: [de,en]

Searching by translated field:, (*7)

...
$repo = $this->em->getRepository("XXXXBundle:Tag");
$translationRepo = $this->em->getRepository("Tuxes3DoctrineUtilBundle:Translation");
$tag = $repo->find($translationRepo->id('Tag', 'name', $name)); // 'Tag' ===> Classname of entity, 'name' ===> fieldname
...

Saving a translation in code:, (*8)

$tag = new Tag();
$tag->setName($name);
$this->em->persist($tag);
$this->em->flush(); // <-- flush is important as instead the id is not set... :/
$translation = new Translation();
$translation->setObjid($tag->getId());
$translation->setField('name');
$translation->setClass('Tag');
$translation->setContent($name);
$translation->setLocale('en');
$this->em->persist($translation);

TODO: * Search with language * more options in formtype rendering * Use Doctrine caching * ..., (*9)

The Versions

28/08 2014

dev-master

9999999-dev

Simple way to translate your entities in forms

  Sources   Download

MIT

The Requires

 

by Nicolo Singer

form entity translation