Email iconarrow-down-circleGroup 8Path 3arrow-rightGroup 4Combined Shapearrow-rightGroup 4Combined ShapeUntitled 2Untitled 2Path 3ozFill 166crosscupcake-icondribbble iconGroupPage 1GitHamburgerPage 1Page 1LinkedInOval 1Page 1Email iconphone iconPodcast ctaPodcast ctaPodcastpushpinblog icon copy 2 + Bitmap Copy 2Fill 1medal copy 3Group 7twitter icontwitter iconPage 1

We’ve just completed our first sprint on internationlising Havells Sylvania’s corporate website. Havells are a global company that previously had multiple websites across brands, languages and countries and their new website aims to consolidate all of that information under one umbrella site, with the same content across lanaguages.

We love the Symfony 2 Framework at UVd, it’s our ‘go-to’ framework for the back-end of our web application development and our Jellybean CMS is built on top of it. We take an agile approach with all the work we do, and until now Jellybean has not required any localisation functionality, fortunately Symfony comes with some really powerful localisation/internationalisation features out of the box and together with Doctrine2 has made it simple to deliver.

Symfony routing and the locale component

Changes like this really demonstrate the power of the Symfony2 routing and localisation components – the route for all of our Jellybean pages were updated as this snippet demonstrates.

The special {_locale} variable in Symfony sets the locale for the whole application and allows us to serve the appropriate content to the user based on their preferred langage. You can access the current locale for a user anywhere you have the request object. Under the hood Symfony 2 updates all your internal links to use the current locale, which is very handy!

Gedmo doctrine extensions

If you use Doctrine for your applications and have not come across the Gedmo set of Doctrine extensions (and Stof’s Symfony2 bundle for them), then I strongly suggest you check them out!

The translatable extension (docs) hooks into Symfony via Stofs bundle, and takes the locale set by the framework to find the corresponding translation for a piece of content, all with some minor updates the models in our application (and very little else!).

It is as simple as installing the packages with composer, and configuring them in the config.yml in your symfony project

And then configuring your entities like so, (omitted is the configuration for the ArticleTranslation entity, but that is well documented in the docs for the gedmo extension)

Thats it! Your application will now be serving translated content (if it exists) based on the locale you have made available, with no other effort.

a2lix translation form bundle

The real challenge came with updating the user interface for content editors to translate their content. Jellybean CMS features live-edit functionality allowing users to see and edit their content as it looks on the page. For that we have the a2lix translation form bundle; Symfony already handles mapping and validating forms to our business entities (in this case our pages) very nicely. The translation form bundle enhances our existing forms adding fields for each supported language, and handling the (seemingly) magic mapping of the translated content to our database by coordinating with the gedmo extensions. Aside from front-end effort, we only had to add this one liner to our existing form:

Staying friendly with the search engines

Google advise that you set up unique urls for each translation, often sites set up confusing cookie/session based techniques for setting your preferred languages, however this prevents people from sharing links in their native language, and has other usability issues – not least it doesn’t give search engines anything to crawl! We currently fall back to English for content that hasn’t been translated, and this can cause issues with duplicate content. We therefore use the canonical link property, and hreflang links that hint to search engines that different language versions of the content is available. There is a great article on google webmaster central explaining some of the different options available.

So what?

Well I believe there are still a dearth of sites out there providing a good experience for non-english speakers. With frameworks like Symfony 2 putting i8n/internationisation at the core of their functionality, and with great community support for the bundles we have utilised, there is really very little excuse not to do a good job. Indeed the speed these packages afforded us allowed us to concentrate on UX/UI and other features which is a win all round! Providing your content in different languages can also have the added benefit of making your site more discoverable & competitive through perhaps under-utilised channels (i.e. language specific search engine sites,, etc).