WARNING: You are browsing the documentation for version 1.0 which is not maintained anymore. If some of your projects are still using this version, consider upgrading.

Multi-Language Support

1.0 version
Maintained Unmaintained

Multi-Language Support

Setting addLocalePattern 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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;

// ...

// pass true as the 3rd parameter to prefix the route pattern with /{_locale}
$page = new Page(false, false, 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();

Since SimpleCmsBundle only provides a single tree structure, all nodes will have the same node name for all languages. So a url http://foo.com/en/hello-world for english content will look like http://foo.com/de/hello-world for german content.

At times it might be most feasible to use integers as the node names and simple append the title of the node in the given locale as an anchor. So for example http://foo.com/de/1#my title and http://foo.com/de/1#mein title. If you need language specific URLs, you want to use the CMF RoutingBundle and ContentBundle directly to have a separate route document per language.

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