Basic i18n in Magnolia: quick tutorial

I18n in Magnolia is quite simple. This tutorial will show how to manage multilanguage sites using Magnolia CMS (from v4.3.1).

Magnolia supports internationalization (i18n) for Dialogs, Paragraphs and Templates. I18n is performed not only for content but also for application labels, like a form “send” button.
To enable i18n for content, simply edit the Paragraph / Template Dialog and add the property “i18n=true” to the fields you want to be internationalized:

Developers do not have to manage anything inside the template files, because i18n is handled by Magnolia in a transparent way. So just write “${content.errorTitle}” and this will output the current language content.
For labels, just enable i18n adding the property “i18nBasename” to a Paragraph / Template definition:

At this point, use this code fragment inside the template file to render a label: ${i18n[‘place.here.your.label.key’]}
Magnolia will look inside the Java classpath, looking for a file called messages_xy.properties (where xy is the current language) placed into the package /info/magnolia/module/form .
That file should be something like this:

Magnolia will look inside this file to find a matching key to output.
I18n settings are configured in the Site definition:

This configuration says that for site ecp-sil the available locales are French, German and English. The default locale is French and it is shown when users visit http://mysite.com. If they visit http://mysite.com/de/ or http://mysite.com/en/ they will see the localized version of the site. If no content has been produced for en or de version, it would be used the one defined by fallbackLocale property. The same is for labels.

Latest articles

Matteo Pelucco Written by:

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *


+ 5 = eleven