Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

Multi-Language Support

1.3 version
Maintained Unmaintained

Multi-Language Support

Setting the option add_locale_pattern to true in a Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page document will result in prefixing the associated route with /{_locale}. Using the native translation capabilities of PHPCR ODM it is now possible to create different versions of the document for each language that should be available on the website.

For example:

use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;

// ...

// pass add_locale_pattern as true to prefix the route pattern with /{_locale}
$page = new Page(array('add_locale_pattern' => true));

$page->setPosition($parent, 'hello-world');
$page->setTitle('Hello World!');
$page->setBody('Really interesting stuff...');
$page->setLabel('Hello World');

$dm->persist($page);
$dm->bindTranslation($page, 'en');

$page->setTitle('Hallo Welt!');
$page->setBody('Super interessante Sachen...');
$page->setLabel('Hallo Welt!');

$dm->bindTranslation($page, 'de');

$dm->flush();

Unless you write your own listener to update the locale before the routing takes place, your content will be loaded in the default locale and you will need to reload the content after the routing step to get the requested locale.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.