Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions gp-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,32 @@ If this parameter is not specified, `upload` goal creates a new Globalization Pi
with all available machine translation target languages, and `download` goal exports all
target languages currently available in the Globalization Pipeline bundle.

#### `<pathToBundleMapper>`

Specifies a mapping rule for converting source bundle file path to Globalization Pipeline bundle
ID. To specify a mapping rule, use one or more `<regexMapper>` elements with pattern and replacement.
A source resource file path relative to the base source directory (`<directory>` value in `<sourceFiles>` element) is used as the input of target path conversion specified by this setting.
For each `<regexMapper>` element, substring matching a Java regular expression pattern specified by
`<pattern>` value will be replaced with the value specified by `<replacement>` value.

The example below will remove `.properties` from a given path, then replace `/` with `.`.
For example, an input path `com/ibm/g11n/example/MyStrings.properties` will produce
a fully qualified Java class name `com.ibm.g11n.example.MyStrings`, which will be used as the
Globalization Pipeline bundle ID for the resource file.

```
<pathToBundleMapper>
<regexMapper>
<pattern>(.+).properties</pattern>
<replacement>$1</replacement>
</regexMapper>
<regexMapper>
<pattern>/</pattern>
<replacement>\.</replacement>
</regexMapper>
</pathToBundleMapper>
```

#### `<languageMap>`

Specifies custom language mappings. Each nested element name is a [BCP 47 language tag](https://tools.ietf.org/html/bcp47)
Expand Down Expand Up @@ -527,6 +553,31 @@ then the French version will be `com/ibm/g11n/fr/MyMessages.properties`.

The default value is **LANGUAGE_SUFFIX**.

*Note: This element is ignored when `<sourcePathToTargetMapper>` is specified.*

#### `<sourcePathToTargetMapper>`

Specifies mapping rule(s) to control output file path in `download` goal. To specify a mapping rule, use one or more `<regexMapper>` elements with pattern and replacement. A source resource file path
relative to the base source directory (`<directory>` value in `<sourceFiles>` element) is used as
the input of target path conversion specified by this setting. For each `<regexMapper>` element,
substring matching a Java regular expression pattern specified by `<pattern>` value will be replaced
with the value specified by `<replacement>` value. The final output path must contain a special
place holder token `%LANG%`, which will be replaced with a target language code.

The example below will replace a folder `en` with `%LANG%`. For example, when a source file path
is `nls/comp1/en/Help.json`, the path will be converted to `nls/comp1/%LANG%/Help.json`. Then,
`%LANG%` will be replaced with language ID (configured by `<languageIdStyle>` and `<languageMap>`).

```
<sourcePathToTargetMapper>
<regexMapper>
<pattern>(.+)/en/([^/]+).json</pattern>
<replacement>$1/%LANG%/$2.json</replacement>
</regexMapper>
</sourcePathToTargetMapper>
```



### Default Configuration

Expand Down
190 changes: 104 additions & 86 deletions gp-maven-plugin/src/it/download-layout/pom.xml
Original file line number Diff line number Diff line change
@@ -1,89 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>@project.groupId@</groupId>
<artifactId>download-layout</artifactId>
<version>@project.version@</version>
<packaging>jar</packaging>
<name>gp-maven-plugin integration test - download-layout</name>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>download</goal>
</goals>
</execution>
</executions>
<configuration>
<bundleSets>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>lang_suffix/*.json</include>
</includes>
</sourceFiles>
<targetLanguages>
<param>fr</param>
<param>zh-Hans</param>
</targetLanguages>
<type>JSON</type>
<bundleLayout>LANGUAGE_SUFFIX</bundleLayout>
</bundleSet>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>lang_only/en.json</include>
</includes>
</sourceFiles>
<targetLanguages>
<param>fr</param>
<param>zh-Hans</param>
</targetLanguages>
<type>JSON</type>
<bundleLayout>LANGUAGE_ONLY</bundleLayout>
</bundleSet>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>lang_dir/en/*.json</include>
</includes>
</sourceFiles>
<targetLanguages>
<param>fr</param>
<param>zh-Hans</param>
</targetLanguages>
<type>JSON</type>
<bundleLayout>LANGUAGE_DIR</bundleLayout>
</bundleSet>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>lang_subdir/*.json</include>
</includes>
</sourceFiles>
<targetLanguages>
<param>fr</param>
<param>zh-Hans</param>
</targetLanguages>
<type>JSON</type>
<bundleLayout>LANGUAGE_SUBDIR</bundleLayout>
</bundleSet>
</bundleSets>
</configuration>
</plugin>
</plugins>
</build>
<groupId>@project.groupId@</groupId>
<artifactId>download-layout</artifactId>
<version>@project.version@</version>
<packaging>jar</packaging>
<name>gp-maven-plugin integration test - download-layout</name>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>download</goal>
</goals>
</execution>
</executions>
<configuration>
<bundleSets>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>lang_suffix/*.json</include>
</includes>
</sourceFiles>
<targetLanguages>
<param>fr</param>
<param>zh-Hans</param>
</targetLanguages>
<type>JSON</type>
<bundleLayout>LANGUAGE_SUFFIX</bundleLayout>
</bundleSet>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>lang_only/en.json</include>
</includes>
</sourceFiles>
<targetLanguages>
<param>fr</param>
<param>zh-Hans</param>
</targetLanguages>
<type>JSON</type>
<bundleLayout>LANGUAGE_ONLY</bundleLayout>
</bundleSet>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>lang_dir/en/*.json</include>
</includes>
</sourceFiles>
<targetLanguages>
<param>fr</param>
<param>zh-Hans</param>
</targetLanguages>
<type>JSON</type>
<bundleLayout>LANGUAGE_DIR</bundleLayout>
</bundleSet>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>lang_subdir/*.json</include>
</includes>
</sourceFiles>
<targetLanguages>
<param>fr</param>
<param>zh-Hans</param>
</targetLanguages>
<type>JSON</type>
<bundleLayout>LANGUAGE_SUBDIR</bundleLayout>
</bundleSet>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>mapper/**/*.json</include>
</includes>
</sourceFiles>
<targetLanguages>
<param>fr</param>
<param>zh-Hans</param>
</targetLanguages>
<type>JSON</type>
<sourcePathToTargetMapper>
<regexMapper>
<pattern>(.+)/en_(.+).json</pattern>
<replacement>$1/translated/%LANG%_$2.json</replacement>
</regexMapper>
</sourcePathToTargetMapper>
<languageIdStyle>BCP47</languageIdStyle>
</bundleSet>
</bundleSets>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key1": "val1"
}
4 changes: 3 additions & 1 deletion gp-maven-plugin/src/it/download-layout/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def outFiles = [
"target/classes/lang_dir/fr/Strings.json",
"target/classes/lang_dir/zh_Hans/Strings.json",
"target/classes/lang_subdir/fr/Strings.json",
"target/classes/lang_subdir/zh_hans/Strings.json"
"target/classes/lang_subdir/zh_hans/Strings.json",
"target/classes/mapper/res/translated/fr_resource.json",
"target/classes/mapper/res/translated/zh-Hans_resource.json"
]

def missing = []
Expand Down
38 changes: 34 additions & 4 deletions gp-maven-plugin/src/it/upload-basic/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,7 +14,39 @@
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@pom.version@</version>

<configuration>
<bundleSets>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</sourceFiles>
</bundleSet>
<bundleSet>
<sourceFiles>
<directory>src/main/resources</directory>
<includes>
<include>**/*_en.json</include>
</includes>
</sourceFiles>
<type>JSON</type>
<pathToBundleMapper>
<regexMapper>
<pattern>(.+)_en.json</pattern>
<replacement>JSON-$1</replacement>
</regexMapper>
<regexMapper>
<pattern>/</pattern>
<replacement>_</replacement>
</regexMapper>
</pathToBundleMapper>
</bundleSet>
</bundleSets>
</configuration>
</plugin>
</plugins>
</build>
</build>
</project>
2 changes: 1 addition & 1 deletion gp-maven-plugin/src/it/upload-basic/setup.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
broker-url=https://gp-fakebroker-unsubscribed-ceriman.au-syd.mybluemix.net/newInstance
credentials=credentials.json
createdbundles=com.bundle1.ResourceBundle,com.bundle2.ResourceBundle,com.bundle3.Bundle_with_spaces
createdbundles=com.bundle1.ResourceBundle,com.bundle2.ResourceBundle,com.bundle3.Bundle_with_spaces,JSON-com_bundle4_Strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key1": "val1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.ibm.g11n.pipeline.maven;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -62,6 +63,11 @@ public class BundleSet {
@Parameter(defaultValue = "LANGUAGE_SUFFIX")
private BundleLayout bundleLayout = BundleLayout.LANGUAGE_SUFFIX;

@Parameter
private List<RegexMapper> pathToBundleMapper;

@Parameter
private List<RegexMapper> sourcePathToTargetMapper;

public BundleSet() {
}
Expand Down Expand Up @@ -206,7 +212,35 @@ public BundleLayout getBundleLayout() {
/**
* @param bundleLayout the bundle layout to set
*/
public void setOutputPathOption(BundleLayout bundleLayout) {
public void setBundleLayout(BundleLayout bundleLayout) {
this.bundleLayout = bundleLayout;
}

/**
* @return the pathToBundleMapper
*/
public List<RegexMapper> getPathToBundleMapper() {
return pathToBundleMapper;
}

/**
* @param pathToBundleMapper the pathToBundleMapper to set
*/
public void setPathToBundleMapper(List<RegexMapper> pathToBundleMapper) {
this.pathToBundleMapper = pathToBundleMapper;
}

/**
* @return the sourcePathToTargetMapper
*/
public List<RegexMapper> getSourcePathToTargetMapper() {
return sourcePathToTargetMapper;
}

/**
* @param sourcePathToTargetMapper the sourcePathToTargetMapper to set
*/
public void setSourcePathToTargetMapper(List<RegexMapper> sourcePathToTargetMapper) {
this.sourcePathToTargetMapper = sourcePathToTargetMapper;
}
}
Loading