If your app uses a
language module or
Language.properties
file for
its user interface messages, you’re in the right place. Language Builder
provides these localization capabilities:
-
Generating language files for each supported locale with a single command. It also propagates new default language file keys to all language files, while keeping their translated values intact.
-
Generating translations automatically using Microsoft’s Translator Text API. This gives you a jump start on creating translations.
Start with Configuring the Language Builder plugin.
Configuring the Language Builder Plugin
Configure the Language Builder plugin for Gradle or Maven.
Gradle:
buildscript {
dependencies {
classpath 'com.liferay:com.liferay.gradle.plugins.lang.builder:latest.release'
}
repositories {
maven {
url "https://repository.liferay.com/nexus/content/repositories/liferay-public-releases/"
}
}
}
apply plugin: "com.liferay.lang.builder"
repositories {
maven {
url "https://repository.liferay.com/nexus/content/repositories/liferay-public-releases/"
}
}
Maven:
<project>
...
<build>
<plugins>
<plugin>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.lang.builder</artifactId>
<version>1.0.30</version>
<configuration>
<langDirName>.</langDirName>
<translateClientId>${microsoft.translator.client.id}</translateClientId>
<translateClientSecret>${microsoft.translator.client.secret}</translateClientSecret>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Now you can invoke Language Builder in your project.
Running Language Builder
When you run Language Builder, it generates properties files for all your
locales and propagates all new language properties from Language.properties
to
your locale language files (newly generated and existing). Additionally if you
configured the Microsoft Translator Text API (discussed next), Language Builder
translates your locale language properties.
Here’s the command:
Gradle:
gradlew buildLang
Maven:
mvn lang-builder:build
Note, until you configure translation credentials (discussed next), Language Builder prints this message:
Translation is disabled because credentials are not specified
If you want to configure your app to generate automatic translations using the Microsoft Translator Text API, keep reading.
Translating Language Keys Automatically
If you’ve configured the Language Builder plugin (above) in your project, you’re well on your way to translating language keys automatically. Now you have to configure Microsoft’s Translator Text API so you can translate language keys automatically.
Here’s how to set up the translator and generate translations.
-
Generate a translation subscription key for the Microsoft Translator Text API. Follow the instructions here.
-
Add your client credentials to the Language Builder plugin configuration. For security reasons, pass the credentials to a property that’s stored in your local build environment (e.g., see the Gradle environment guide).
Gradle:
Make sure the
buildLang
task knows to use your subscription key for translation by setting thetranslateSubscriptionKey
property:buildLang { translateSubscriptionKey = langTranslateSubscriptionKey }
Here’s the entire
build.gradle
example code,buildscript { dependencies { classpath 'com.liferay:com.liferay.gradle.plugins.lang.builder:latest.release' } repositories { maven { url "https://repository.liferay.com/nexus/content/repositories/liferay-public-releases/" } } } apply plugin: "com.liferay.lang.builder" buildLang { translateSubscriptionKey = langTranslateSubscriptionKey } repositories { maven { url "https://repository.liferay.com/nexus/content/repositories/liferay-public-releases/" } }
Maven:
Set the following Language Builder plugin
<translateClientId />
and<translateClientSecret />
configuration elements using Maven build environment properties:<configuration> <langDirName>.</langDirName> <translateClientId>${microsoft.translator.client.id}</translateClientId> <translateClientSecret>${microsoft.translator.client.secret}</translateClientSecret> </configuration> ...
Here’s the entire
pom.xml
example code,<project> ... <build> <plugins> <plugin> <groupId>com.liferay</groupId> <artifactId>com.liferay.lang.builder</artifactId> <version>1.0.30</version> <configuration> <langDirName>.</langDirName> <translateClientId>${microsoft.translator.client.id}</translateClientId> <translateClientSecret>${microsoft.translator.client.secret}</translateClientSecret> </configuration> </plugin> </plugins> </build> ... </project>
-
Run Language Builder.
Gradle:
gradlew buildLang
Maven:
mvn lang-builder:build
Great! You can now generate language files and provide automatic translations of your language keys.