Fórum

A possible bug with LanguageUtil

Csaba Meszaros, modificado 7 Anos atrás.

A possible bug with LanguageUtil

Junior Member Postagens: 42 Data de Entrada: 10/10/13 Postagens Recentes
I have Language.properties files in /resources/content, which are defined and visible on JSP pages. In a portlet class, however the following code doesn't seem to work:

String myValue=LanguageUtil.get(user.getLocale(),"my.key");

user.getLocale() is defined, the key exist, but it returns "my.key".

This is happening on LR 7.0 GA3, Linux.
thumbnail
David H Nebinger, modificado 7 Anos atrás.

RE: A possible bug with LanguageUtil

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
When you get the key you pass in, that means that it cannot find a replacement value so you just get the key instead.

LanguageUtil does not check your local message bundles, it only pulls from the Liferay message bundles.
Csaba Meszaros, modificado 7 Anos atrás.

RE: A possible bug with LanguageUtil

Junior Member Postagens: 42 Data de Entrada: 10/10/13 Postagens Recentes
So what would be the correct way of obtaining the key value from portal's local Language.properties file.
Your answer would be much better if you'd give a working answer. Of course if it is not a top secret in Liferay Inc. emoticon
thumbnail
David H Nebinger, modificado 7 Anos atrás.

RE: A possible bug with LanguageUtil

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
So normally we don't do backend language bundle handling, instead that is left to the front end.

For backend, you need to get access to your ResourceBundle, and typically you can get there from the PortletConfig object:

PortletConfig portletConfig = (PortletConfig)actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
ResourceBundle rb = porteltConfig.getResourceBundle(userLocale);


Once you have the RB you can grab a localized string.
Csaba Meszaros, modificado 7 Anos atrás.

RE: A possible bug with LanguageUtil

Junior Member Postagens: 42 Data de Entrada: 10/10/13 Postagens Recentes
Thanks! This is what I was looking for. emoticon