Liferay’s localization framework helps you create and use localized messages
in minutes. You create your messages in a default properties file called
Language.properties
and localize them in properties files that use the
convention Language_xx.properties
, where xx
is the locale code. After
deploying your app, the messages are available to your templates. Liferay’s JSP
tags, such as <liferay-ui:message .../>
display them in the user’s current
locale automatically, without requiring you to access
ResourceBundle
or Locale
objects explicitly. Here are the steps:
-
Create a default language properties file called
Language.properties
in your project’s resource bundle folder.Project Type Resource Bundle Folder Bean Portlet src/main/resources/content/
JSF Portlet src/main/resources/
Liferay MVC Portlet src/main/resources/content/
PortletMVC4Spring Portlet src/main/java/resources/content/
Angular Widget features/localization/
React Widget features/localization/
Vue.js Widget features/localization/
-
Specify your language properties (language keys) using key/value pairs. For example, create a friendly greeting.
howdy-partner=Howdy, Partner!
-
Configure your app’s resource bundle and the locales you’re supporting. The locales your Liferay DXP instance supports are specified in its portal properties file (here are Liferay DXP’s default locales. For example, these configurations support translations for English and Spanish locales:
@PortletConfiguration
class annotation: Can be used in Portlet 3.0 portlets such as Bean Portlets.@PortletConfiguration ( ... resourceBundle="content.Language", supportedLocales = {"en", "es"} )
Portlet descriptor
portlet.xml
: Can be used in any portlet WAR.<portlet> ... <supported-locale>en</supported-locale> <supported-locale>es</supported-locale> <resource-bundle>content.Language</resource-bundle> ... </portlet>
@Component
class annotation: Can be used in a portlet module such as a Liferay MVC Portlet.@Component ( ... property = { ... "javax.portlet.supported-locale=en", "javax.portlet.supported-locale=es", "javax.portlet.resource-bundle=content.Language" } )
-
Create language properties for a locale. For demonstration purposes, create one manually. Automatically generating translations is discussed later.
For example, create a Spanish translation by copying
Language.properties
toLanguage_es.properties
and translating the property values to Spanish.howdy-partner=Hola, Compañero!
-
In your front-end template code, use the language property. For example, a JSP could use the
howdy-partner
property via the<liferay-ui:message />
tag.<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> ... <liferay-ui:message key="howdy-partner" /> ...
-
Deploy your application and view it in different locales. For example, you could view the app locally in Spanish by specifying the
es
locale code in the URL (e.g.,http://localhost:8080/es/...
).
Congratulations on a great start to localizing your application!
Next, you can explore generating translations automatically or create a language module for using language keys across applications.