Language Localization

There are three ways to get localized language / text in Liferay. This is usually refers to get a value from content/Language*.properties by using a key. You can get this value from the following  files :

  1. From java class
  2. From jsp page
  3. From javascript file

For java classes, you can get localized text / content from Language*.properties by using com.liferay.portal.kernel.language.LanguageUtil class. There are a few methods there to get localized text, for example :

     LanguageUtil.get(locale, key);

You can just pass the locale and the key, then you’ll get localized text.

In jsp file, you can use the same class to get localized text, where you can pass the locale, or pageContext. You can also use <liferay-ui message> tag if you prefer to use taglib.Taglib definition can be found on /util-taglib/src/META-INF/liferay-ui.tld file.

In javascript file, you can get localized text by calling language servlet in com.liferay.portal.servlet.LanguageServlet class using AJAX. But Liferay already make our life easier by providing javascript API for this. You can just call


. This javascript API is defined in portal-web/docroot/html/js/liferay/language.js file. This javascript will automatically detect your locale, so you only need to pass your key.

1 comment so far

  1. Xinsheng Chen on

    Thank you! You are a localization expert at Liferay portal!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: