How to Add Language Key in Liferay: JSP, Fragments, and Templates

Author: Ajay Choudhary

Liferay Version: 7.2, 7.3, 7.4

In Liferay, you can add language key in liferay in JSP, Fragments, and Templates (e.g., FreeMarker) to make your application multilingual. Here’s how to do it in each case:

Adding Language Key in JSP

In a JSP file, you can use Liferay’s <liferay-ui:message> tag to retrieve and display the language key value.

First you will have to import the liferay-ui tag library.

<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>

You can use a language key in your JSP

<liferay-ui:message key="your-language-key" />

Adding Language Key in Fragment

In a Liferay Fragment, You can use the @liferay.langauge method to access the language key.

[@liferay.language key="your-language-key" /]

Adding Language Key in widget template or web content template

In templates, You can use the languageUtil.get or @liferay.langauge method to access the language key.

${languageUtil.get(locale, "your-language-key")}
<@liferay.language key="your-language-key" />

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

close
Thanks !

Thanks for sharing this, you are awesome !