Generating Translations Automatically

Liferay DXP supports 50 languages out-of-the-box. Each locale has its own language properties file containing keys for its language.

When you create an application with custom language keys, it’s tedious and difficult to translate them for all these different languages. Fortunately, you can use Liferay’s Language Builder tool to generate translations automatically. Language Builder generates translations 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:2024.q1.1

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/dxp/latest/en/liferay/development/liferay-internals/extending-liferay/customizing-localization/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 = ["fa"]
}

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

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy