Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
Puj Z
reading from language bundle in a java file
April 16, 2012 1:08 AM

Puj Z

Rank: Regular Member

Posts: 220

Join Date: January 14, 2010

Recent Posts

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,
Siby Mathew
RE: reading from language bundle in a java file
August 3, 2012 8:46 AM

Siby Mathew

Rank: Expert

Posts: 268

Join Date: March 4, 2011

Recent Posts

I have used the following code to retrieve the specific language value :
1final PortletConfig portletConfig = (PortletConfig) actionRequest
2                .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
3        // Return language file specific to the locale
4        return LanguageUtil.get(portletConfig, locale, key);

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!