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 :
- From java class
- From jsp page
- 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
Liferay.Language.get("your-language-key")
. 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.
Thank you! You are a localization expert at Liferay portal!