Customizing Localization

Generating Translations Automatically

Liferay includes translations for more than 45 languages. When you build an application with custom language keys, translating them into all those languages by hand is tedious. Liferay’s Language Builder tool generates the translations for you, using Microsoft’s Translator API.

Note

The accuracy and correctness of machine translation can vary from language to language. Use them at your own risk.

See the Sample Project

Start a new Liferay DXP instance by running

docker run -it -m 8g -p 8080:8080 liferay/dxp:2026.q1.9-lts

Sign in to Liferay at http://localhost:8080 using the email address test@liferay.com and the password test. When prompted, change the password to learn.

Then, follow these steps:

  1. Download and unzip Automatically Generating Translations.

    curl https://resources.learn.liferay.com/examples/liferay-m7d6.zip -O
    
    unzip liferay-m7d6.zip
    
  2. Open the gradle.properties file in the module root folder. Add your Microsoft Translator subscription key:

    microsoft.translator.subscription.key=[your unique key]
    

    Note for Language Builder to work, you must obtain your own Microsoft Translator subscription key.

  3. From the module root, run Language Builder.

    ./gradlew buildLang
    

    In your terminal window, Language Builder generates the different language properties files. Note, if you see the error Translation is disabled because credentials are not specified, double-check that your subscription key is correct.

  4. Navigate to the module’s src/main/resources/content folder to view the translated properties files.

The properties files are found in the src/main/resources/content folder.

Adding Your Language Keys

The sample project has one language key in the Language.properties file. Add as many language keys as you need for your application, then run Language Builder.

To deploy the language keys to Liferay, see Overriding Global Language Translations with Language Properties. The instructions are the same whether overriding existing keys or adding new keys.

If you want to exclude some languages from being translated automatically, use the excludedLanguageIds property in your project’s build.gradle file. For example, to exclude French,

buildLang {
	excludedLanguageIds = ["fr"]
}

To learn more about the Language Builder tool and additional configuration, see Lang Builder Gradle Plugin.