Globalizaton Pipeline Ant Task is an antlib designed for integrating Globalization Pipeline service with Apache Ant. The antlib includes custom tasks for uploading translatable resource bundles from local file system to an instance of Globalization Pipeline service and downloading translated resource bundles to local file system.
This antlib runs on Java Runtime Environment 7 or later versions. The minimum ant version is 1.9.
To setup Globalization Pipeline Ant Task
- Download the Globalization Pipeline Ant Task jar file (gp-ant-task-X.X.X-with-dependencies.jar) from the official release page.
- Set up name space for the Globalization Pipleline tasks and task definition in your Ant build.xml as below.
<?xml version="1.0" encoding="utf-8" ?>
<project name="My Project" xmlns:gp="antlib:com.ibm.g11n.pipeline.ant">
<taskdef uri="antlib:com.ibm.g11n.pipeline.ant" resource="com/ibm/g11n/pipeline/ant/antlib.xml">
<classpath path="${path-to-gp-jar}/gp-ant-task-X.X.X-with-dependencies.jar"/>
</taskdef>
Note: You might place Globalization Pipeline Ant Task jar file in your Ant installations
library directory ($ANT_HOME/lib). In this case, Ant will automatically find the task
definitions without <taskdef>
declaration.
Following Ant tasks are currently available.
Task | Description |
---|---|
upload | Upload translatable resource bundle files from local file system to an instance of Globalization Pipeline service. |
download | Download translated resource bundles from an instance of Globalization Pipeline service to local file system. |
The ant task requires service instance administrator credentials for a Globalization Pipeline service instance. Please refer Quick Start Guide to see how to get service credentials information of your Globalization Pipeline instance.
There are two ways to specify the service credentials.
The ant task can read service credentials from a JSON file. The JSON file must contain "url", "userId", "password" and "instanceId" fields as below.
{
"url": "https://gp-rest.ng.bluemix.net/translate/rest",
"userId": "f02d4de9f115cc8b6e8c75a6c995f075",
"password": "YOfm4qhW8D4stazDL7cBOBB1YV+kf1qa",
"instanceId": "d38f803b34a3aa36e39174bcf2d5f941"
}
Note: This is an example. You must replace field values with actual values used by your Globalization Pipeline service instance.
In your Ant build.xml, specify the JSON file in credentialsJson attribute in each Globalization Pipeline Ant task as below:
<target name="upload-resources">
<gp:upload credentialsJson= "gpcreds.json" sourceDir="src/main/resources"/>
</target>
The service credentials can be also embedded in build.xml
using <credentials>
tag
as below.
<target name="upload-resources">
<gp:upload sourceDir="src/main/resources">
<credentials url="https://gp-rest.ng.bluemix.net/translate/rest"
userId="f02d4de9f115cc8b6e8c75a6c995f075"
password="YOfm4qhW8D4stazDL7cBOBB1YV+kf1qa"
instanceId="d38f803b34a3aa36e39174bcf2d5f941"/>
</gp:upload>
</target>
Note: This is an example. You must replace attribute values with actual values used by Globalization Pipeline service instance.
build.xml below illustrates basic use cases of the ant tasks:
<?xml version="1.0" encoding="utf-8"?>
<project name="Example Project" xmlns:gp="antlib:com.ibm.g11n.pipeline.ant">
<taskdef uri="antlib:com.ibm.g11n.pipeline.ant" resource="com/ibm/g11n/pipeline/ant/antlib.xml">
<classpath path="my-antlib-dir/gp-ant-task-X.X.X-with-dependencies.jar"/>
</taskdef>
<!--Specify the location of the credentials json file -->
<property name="gp.credentials" value="creds.json"/>
<!-- Uploads .properties files in sourceDir to the Globalization Pipelne service instance -->
<target name="upload-resources">
<gp:upload credentialsJson= "${gp.credentials}" sourceDir="src/main/resources" />
</target>
<!-- Downloads translated .properties files from the Globalization Pipeline services intances to outputDir -->
<target name="download-translations">
<gp:download credentialsJson="${gp.credentials}" sourceDir="src/main/resources" outputDir="target/classes" />
</target>
</project>
The ant target upload-resources
in the example above does following operations:
-
Scans files under
src/main/resources
(sourceDir attribute) and locates files with.properties
extension (but excluding files with '_'(underscore) character in its file name, such asMessages_fr.properties
). -
For each Java property resource bundle file, checks if corresponding Globalization Pipeline bundle already exists or not. If it's not available, creates a new bundle with all translation target languages currently configured in Machine Translation. English is used as the translation source language.
-
Extracts resource strings from each file, and uploads them to the matching Globalization Pipeline bundle as the translation source.
This task will synchronize the contents of a Globalization Pipeline bundle with the contents of local file. When a resource key was deleted from local file, it will be also deleted from the corresponding Globalization Pipeline bundle. If a resource string value was changed, this operation refreshes the corresponding resource string's value, which eventually triggers re-translation. When the contents is not changed since last invocation, this operation does not make any changes in the Globalization Pipeline bundles.
So the best practice would be invoking the task when any changes were made in translatable resource bundle files, although it's not harmful to invoke the goal at any time.
This ant target download-translations
above does following operations:
-
Scans files under
src/main/resources
(sourceDir attribute) and locates Java property resource bundle files. This is same as in the upload goal. -
For each Java property resource bundle file, looks up corresponding Globalization Pipeline bundle in the instance of Globalization Pipeline service.
-
If matching Globalization Pipeline bundle is found, copies the contents of source bundle file in local system, extracts resource strings from the Globalization Pipeline bundle, then replaces resource string values with ones extracted from the Globalization Pipeline bundle. The result file is generated under the standard build output directory (
target/classes
) (outputDir attribute) with language suffix, such asMessages_fr.properties
for French. This operation is done for all available target languages in the Globalization Pipeline bundle.
The upload task should be configured using gp:upload
task definition. The attributes and nested elements
of gp:upload
are described below:
Attribute | Description | Required |
---|---|---|
credentialsJson | Specifies the pathname of Globalization Pipeline Instance credentials file | Yes (if the nested element credentials is not used) |
sourceDir | Specifies the pathname for the location where all the relevant bundle files to be uploaded are kept | Yes |
Attribute | Description | Required |
---|---|---|
url | Specifies the instance url | Yes |
userId | Specifies the userId | Yes |
password | Specifies the password | Yes |
instanceId | Specifies the instance id | Yes |
Attribute | Description | Required |
---|---|---|
lang | Specifies the MT language which the uploaded file should be translated to | Yes |
Attribute | Description | Required |
---|---|---|
type | Type of resource bundle file (JSON, JAVA (properties), AMDJS, ...) | No, defaults to JAVA properties file format |
sourceLanguage | Specifies BCP 47 language tag for the language used in the source bundles | No, The default language of en is used |
languageIdStyle | Specifies one of following keywords to configure the rule for composing language ID used for output resource bundle file or path name.
|
No, The default value is BCP47_UNDERSCORE |
Attribute | Description | Required |
---|---|---|
lang | Specifies the MT language which the uploaded file should be translated to | Yes |
Attribute | Description | Required |
---|---|---|
dir | Specifies the source directory location for the bundleSet to be used as reference | Yes |
includes | Specifies the file pattern that needs to be included for uploading | No, but recommended |
excludes | Specifies the file pattern that needs to be excluded for uploading | No |
The download task should be configured using gp:download
task definition. The attributes and nested elements
of gp:download
are described below:
Attribute | Description | Required |
---|---|---|
credentialsJson | Specifies the pathname of Globalization Pipeline Instance credentials file | Yes (if the nested element credentials is not used) |
sourceDir | Specifies the pathname for the location where all the relevant bundle files to be referenced for download are kept | Yes |
outputDir | Specifies the pathname for the location where all the resource bundle files should be downloaded | No, defaults to target/classes directory |
Attribute | Description | Required |
---|---|---|
url | Specifies the instance url | Yes |
userId | Specifies the userId | Yes |
password | Specifies the password | Yes |
instanceId | Specifies the instance id | Yes |
Attribute | Description | Required |
---|---|---|
lang | Specifies the MT language which the uploaded file should be translated to | Yes |
Attribute | Description | Required |
---|---|---|
type | Type of resource bundle file (JSON, JAVA (properties), AMDJS, ...) | No, defaults to JAVA properties file format |
sourceLanguage | Specifies BCP 47 language tag for the language used in the source bundles | No, The default language of en is used |
languageIdStyle | Specifies one of following keywords to configure the rule for composing language ID used for output resource bundle file or path name.
|
No, The default value is BCP47_UNDERSCORE |
outputDir | Specifies the output base directory for this bundleSet | No, If not specified, outputDir specified at gp:download level is used |
outputContentOption | Specifies one of following keywords to control how download goal generates the contents of translated resource bundle files.
|
No, The default value is MERGE_TO_SOURCE. |
bundleLayout | Specifies one of following keywords to control output file name or path in download goal.
|
No, The default value is LANGUAGE_SUFFIX. |
Attribute | Description | Required |
---|---|---|
lang | Specifies the MT language which the uploaded file should be translated to | Yes |
Attribute | Description | Required |
---|---|---|
from | Specifies the language code used in bundle files/directories which needs to be downloaded | Yes |
to | Specifies the language code to be used when naming the downloaded file/directory | Yes |
Attribute | Description | Required |
---|---|---|
dir | Specifies the source directory location for the bundleSet to be used as reference | Yes |
includes | Specifies the file pattern that needs to be included for reference when downloading | No, but recommended |
excludes | Specifies the file pattern that needs to be excluded for reference | No |
example
directory contains some usage examples. Please read the
instruction.