Multilanguage Portlets

Hey,

I’m developing portlets with Vaadin in a Liferay Portal , mostly with english component captions(names) like “Cancel” “back” “next” and so on. Now i have to make the portlets “Multilanguage ready” that means if an user has set the language of his Liferay page to english he should see my portlet captions in english , but if an user sets the language of his Liferay page to german, the portlet captions should be displayed in german.

Is there a way to check wich language the user has set as his main Language ?

an easy Example :

John is from New York his main language is english so as soon as he logins to his account the language of the Portlet component captions should be displayed in english

Heinz is from Berlin his main language is german so as soon as he logins to his account the language of the Portlet component captions should be displayed in german.

Liferay has pretty nice internationalization support so this is not really hard. What you need to do is:

In your portlet.xml add a new resource bundle <portlet> ... <resource-bundle>content.Language</resource-bundle>

Create a new file with the default translations which are used if no other translations are found. Create file in
docroot/WEB-INF/src/Language.properties
. The content of the file is key-value pairs like so: first-name=1st Name nick-name=Nick

Create another translation file with another language, for instance german in
docroot/WEB-INF/src/Language_de.properties
. Use the same keys as in the default translation file.

Finally, when you want to create a translated string in your Java code use LanguageUtil.get(…) to get the translated string. For instance in your button you can do Button.setCaption(LanguageUtil.get(locale, “first-name”)) etc.