留言板

A possible bug with LanguageUtil

Csaba Meszaros,修改在7 年前。

A possible bug with LanguageUtil

Junior Member 帖子: 42 加入日期: 13-10-10 最近的帖子
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,修改在7 年前。

RE: A possible bug with LanguageUtil

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
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,修改在7 年前。

RE: A possible bug with LanguageUtil

Junior Member 帖子: 42 加入日期: 13-10-10 最近的帖子
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,修改在7 年前。

RE: A possible bug with LanguageUtil

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
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,修改在7 年前。

RE: A possible bug with LanguageUtil

Junior Member 帖子: 42 加入日期: 13-10-10 最近的帖子
Thanks! This is what I was looking for. emoticon