Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Daniel Rodriguez
(RESOLVED) Languages.properties in a .war standalone portlet
February 27, 2008 12:38 AM
Answer

Daniel Rodriguez

Rank: Junior Member

Posts: 38

Join Date: August 9, 2006

Recent Posts

Hello all,

I'm developing a .WAR standalone portlet with Eclipse Lomboz and I need to add some keys in the languages files. To ask for them in the JSP pages, as for example:
1<liferay-ui:message key="overall" />


As I'm not working with in the /ext environment I don't know where should I place the language-ext.properties or wich is the file I need to write the new languages keys. I didn't see any language file in the Struts .war portlet overview.

Thanks in advance!
Jorge Ferrer
RE: Languages.properties in a .war standalone portlet
February 24, 2008 9:03 AM
Answer

Jorge Ferrer

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2768

Join Date: August 31, 2006

Recent Posts

Hi Daniel,

I've never used it in a WAR portlet but that tag reads the StrutsBundle from portlet.xml, so I would recommend setting the location of your messages file there.
Daniel Rodriguez
RE: Languages.properties in a .war standalone portlet
February 27, 2008 12:39 AM
Answer

Daniel Rodriguez

Rank: Junior Member

Posts: 38

Join Date: August 9, 2006

Recent Posts

Hi all,

Thanks jorge! I finally did it (with friend helps emoticon using the resource bundle. Here I copy the solution for anyone who need it.

First we create a LanguageUtil class:
 1public class LanguageUtil {
 2   
 3    private Locale locale;
 4    private ResourceBundle bundle;
 5   
 6    public LanguageUtility (ThemeDisplay themeDisplay) {
 7        this.locale = themeDisplay.getUser().getLocale();
 8        bundle = ResourceBundle.getBundle("messages", this.locale);
 9    }
10   
11    public String getString(String key) {
12        try {
13            return bundle.getString(key);   
14        } catch (Exception e) {
15            e.printStackTrace();
16            return key;
17        }
18    }
19}


After we import it in the JSP pages where we need to use it and we have to create an object:
1LanguageUtility lUtil = new LanguageUtility(themeDisplay);


Everytime we need one of our language strings, we use:
1<%=lUtil.getString("key") %>


The messages files are located in /WEB-INF/classes (messages_*.properties)

I hope it helps someone and thank you for your time!