留言板

reading from language bundle in a java file

thumbnail
Puj Z,修改在12 年前。

reading from language bundle in a java file

Regular Member 帖子: 220 加入日期: 10-1-14 最近的帖子
Hi Community,

I am trying to read the translation of a key in a java class with this code (in my ModelLocalServiceImpl), but it is not returning the translation:
String translation = LanguageUtil.format(new Locale("fa_IR"), my-key,null);

Does anyone know what I am doing wrong? The bundle settings are ok, because I see the translation in jsps (by using liferay:ui-message)

Thanks for any helps in advance,
Puj
Siby Mathew,修改在11 年前。

RE: reading from language bundle in a java file

Expert 帖子: 268 加入日期: 11-3-4 最近的帖子
Hi,
I have used the following code to retrieve the specific language value :
final PortletConfig portletConfig = (PortletConfig) actionRequest
                .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
        // Return language file specific to the locale
        return LanguageUtil.get(portletConfig, locale, key);