Automatically Generating Translations
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.
The accuracy and correctness of machine translation can vary from language to language. It is up to you on how to make use of these generated translations.
See the Sample Project
Start a new Liferay DXP instance by running
docker run -it -m 8g -p 8080:8080 liferay/dxp:7.4.13-u55
Sign in to Liferay at http://localhost:8080 using the email address [email protected] and the password test. When prompted, change the password to learn.
Then, follow these steps:
Download and unzip Automatically Generating Translations.
curl https://resources.learn.liferay.com/dxp/latest/en/building-applications/core-frameworks/localization/liferay-m7d6.zip -O
unzip liferay-m7d6.zip
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 need to obtain your own Microsoft Translator subscription key.
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.Navigate to the module’s
src/main/resources/content
folder to view the translated properties files.
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 Keys. 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 include French,
buildLang {
excludedLanguageIds = ["fa"]
}
To learn more about the Language Builder tool and additional configuration, see Lang Builder Gradle Plugin.