Sharing Localized Messages¶
As you work on an application you might have multiple modules, each of which has its own language keys. Instead of maintaining various language properties files in different places, consolidate them into one place. This example project demonstrates how language keys can be shared across different modules.
Run the Tutorial Code¶
Start Liferay DXP. If you don’t already have a docker container, use
docker run -it -m 8g -p 8080:8080 liferay/dxp:7.3.10-dxp-1
If you’re running a different Liferay Portal version or Liferay DXP, adjust the above command accordingly.
Download and unzip Sharing Localized Messages.
curl https://learn.liferay.com/dxp/latest/en/developing-applications/developing-a-java-web-application/using-mvc/liferay-u8t2.zip -O
From the module root, build and deploy.
./gradlew deploy -Ddeploy.docker.container.id=$(docker ps -lq)
This command is the same as copying the deployed jars to
/opt/liferay/osgi/moduleson the Docker container.
Confirm the deployment in the Liferay Docker container console.
STARTED com.acme.u8t2.impl_1.0.0  STARTED com.acme.u8t2.web_1.0.0 
Verify that the example module is working. Open your browser to
Add the U8T2 Portlet to a page. You can find the example portlet under Sample Widgets.
You see the welcome message header and a list of colors. Note that the language keys for colors come from the shared language keys. The language key
colorscomes from Liferay’s global language keys.
This example project also includes locales for Portuguese and Japanese. For example, use the language selector to select Brazilian Portuguese or Japanese to see the welcome message and list of colors.
Now it’s time to learn how it works.
Create the Language Properties File¶
Create a separate project module to hold all the shared language keys. In the example project, the shared keys are in the
Acme U8T2 Impl module.
Language.properties file and add it to the module’s
src/main/resources/content folder. In the file define the keys you want to share with the other modules.
The example project has a list of six colors used by the
Acme U8T2 Web module:
blue=Blue green=Green orange=Orange purple=Purple red=Red yellow=Yellow
Language property files for other locales can also be included in the folder. For example, to include language keys for Japanese, add a
Language_ja.properties file to the folder.
Add the bnd Instruction¶
For each module that you want to share language keys with, you must specify the resource in the bnd header.
Bundle-Name: Acme U8T2 Web Bundle-SymbolicName: com.acme.u8t2.web Bundle-Version: 1.0.0 -liferay-aggregate-resource-bundles: com.acme.u8t2.impl
The example project has a web portlet that uses the color language keys from
Acme U8T2 Impl. In the
bnd.bnd file of the
Acme U8T2 Web module, the resource bundle is specified:
Note that you can still choose to place some language keys in an individual module. For example, the welcome message in the example project comes from the
Acme U8T2 Web module’s language keys and not the shared keys of
Acme U8T2 Impl. Language keys of an individual module take priority over any shared keys specified by
Not finding what you're looking for?
Pardon our dust as we revamp and transition our product documentation to this site. If something seems missing, please check Liferay Help Center documentation for Liferay DXP 7.2 and previous versions.Try Liferay's Help Center