Wandi/I18nBundle is a Symfony bundle used to assist internationalization of projects.
$ composer require wandi/i18n-bundle
$bundles = [
// ...
new \Wandi\I18nBundle\WandiI18nBundle(),
];
- Add TranslatableEntity trait in your Entity.
- Create many fields as needed foreach languages used.
class Foo
{
use TranslatableEntity;
// ...
/**
* @var string
*
* @ORM\Column(name="bar_fr", type="string", length=255)
*/
private $barFr;
/**
* @var string
*
* @ORM\Column(name="bar_en", type="string", length=255)
*/
private $barEn;
}
- The trait will automatically use the correct getter depending to the current language used.
{{ Foo.bar }}
$foo->getBar();