Forums

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

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

Puj Z

Rank: Regular Member

Posts: 213

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

Siby Mathew

Rank: Expert

Posts: 261

Join Date: March 4, 2011

Recent Posts

Hi,
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);