PHP code example of nercury / translation-editor-bundle

1. Go to this page and download the library: Download nercury/translation-editor-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nercury / translation-editor-bundle example snippets


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

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';
    }
}

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

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;
}