Creating a Language Module

You might have an application with multiple modules that provide the view layer. These modules are often called web modules. For example, this application contains three such modules:

my-application/
my-application-web/
my-admin-application-web/
my-application-content-web/
my-application-api/
my-application-service/

Each of these modules can have language keys and translations to maintain, likely resulting in duplicate keys. You don’t want to end up with different values for the same key, and you don’t want to maintain language keys in multiple places. In this case, you should create a single module—a language module—for housing all your app’s language keys.

Follow these steps to create a language module:

  1. In the root project folder (the one that holds your service, API, and web modules), create a new module to hold your app’s language keys.

  2. In the language module, create a src/main/resources/content folder. In this folder, create a Language.properties file for your app’s default language keys. For example, such a file might look like this:

    my-app-title=My Application
    add-entity=Add Entity
    
  3. Create any translations you want in additional language properties files, appending the locale’s ID to the file name. For example, a file Language_es.properties holds Spanish (es) translations and could contain something like this:

    my-app-title=Mi Aplicación
    add-entity=Añadir Entity
    

    Here’s the folder structure of an example language module called my-application-lang. This module contains the app’s default language keys (Language.properties) and a Spanish translation (Language_es.properties):

    my-application-lang/
        bnd.bnd
        src/
            main/
                resources/
                    content/
                        Language.properties
                        Language_es.properties
                        ...
    

On building the language module, Liferay DXP’s ResourceBundleLoaderAnalyzerPlugin detects the module’s Language.properties file and adds a resource bundle capability to the module. A capability is a contract a module declares to the OSGi framework. Capabilities let you associate services with modules that provide them. In this case, Liferay DXP registers a ResourceBundleLoader service for the resource bundle capability.

Overriding Language Keys

Localizing Your Application

Using Liferay’s Localization Settings

Using a Language Module

« Using Liferay's Localization SettingsUsing a Language Module »
Was this article helpful?
0 out of 0 found this helpful