PHP code example of braune-digital / translation-base-bundle

1. Go to this page and download the library: Download braune-digital/translation-base-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/ */

    

braune-digital / translation-base-bundle example snippets


public function registerBundles()
    {
        $bundles = array(
          ...
          new BrauneDigital\TranslationBaseBundle\BrauneDigitalTranslationBaseBundle(),
          ...
        );



namespace YourBundle\Entity;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;

/**
 * Entity
 */
class Entity
{
    use ORMBehaviors\Translatable\Translatable;
    use \BrauneDigital\TranslationBaseBundle\Model\Translatable\TranslatableMethods {
        \BrauneDigital\TranslationBaseBundle\Model\Translatable\TranslatableMethods::proxyCurrentLocaleTranslation insteadof ORMBehaviors\Translatable\Translatable;
    }

    /**
     * @var int
     */
    private $id;

    /**
     * @param $method
     * @param $arguments
     * @return mixed
     */
    public function __call($method, $arguments)
    {
        return $this->proxyCurrentLocaleTranslation($method, $arguments);
    }

    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    

    /**
     * @return mixed
     */
    public function getTitle() {
        $title = $this->translate()->getTitle();
        if ($title) {
            return $title;
        } else {
            return $this->translate($this->getDefaultLocale())->getTitle();
        }
    }

    /**
     * __toString
     *
     * @return string
     */
    public function __toString()
    {
        return $this->getTitle();
    }
}



namespace YourBundle\Entity;

use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
 * EntityTranslation
 */
class EntityTranslation
{

    use ORMBehaviors\Translatable\Translation;

    /**
     * @var string
     */
    protected $title;

    /**
     * @return string
     */
    public function getTitle() {
        return $this->title;
    }

    /**
     * @param string $title
     */
    public function setTitle($title) {
        $this->title = $title;
    }
}



namespace YourBundle\Admin;

use BrauneDigital\TranslationBaseBundle\Admin\TranslationAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;

class EntityAdmin extends TranslationAdmin
{
    // Fields to be shown on create/edit forms
    protected function configureFormFields(FormMapper $formMapper)
    {
		$this->setCurrentLocale();
		$this->buildTranslations($this->subject);

        $formMapper
            ->with('Localization')
			->add('translations', 'a2lix_translations', array(
                'locales' => $this->currentLocale,
                'itle')
        ;
    }
}