Skip to main content

Usage of LanguageUtil class in Liferay

· One min read
Sandeep Bhardwaj

For fetching properties based on locale from properties file in liferay is easy. Use get() method of com.liferay.portal.kernel.language.LanguageUtil class of liferay. It will automatically pick the correct locale file and return the property value.

There are 6 overloaded get methods in LanguageUtil class.

get(Locale locale, String key): StringLanguageUtil  
get(Locale locale, String key, String defaultValue) StringLanguageUtil
get(PageContext pageContext, String key) StringLanguageUtil
get(PageContext pageContext, String key, String defaultValue) StringLanguageUtil
get(PortletConfig portletConfig, Locale locale, String key) StringLanguageUtil
get(PortletConfig portletConfig, Locale locale, String key, String defaultValue) StringLanguageUtil

Usage

<%@page import="com.liferay.portal.kernel.language.LanguageUtil"%>  
<%
String propertyValue=LanguageUtil.get(pageContext, "property_name", new String("NOT_FOUND"));
%>

Argument of get method :-

1st: page context.
2nd: property name whose value to be fetched.
3rd: default value return by get method, if property not found.