Skip to content

Commit 5c902a6

Browse files
authored
Merge pull request #86 from IBM-Cloud/85-truncate-srcSuffix
truncate source suffix in target resource files
2 parents e364931 + f4c89b2 commit 5c902a6

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"upload.desc":"description",
3+
"upload.comment":"comment",
4+
"upload.submit":"upload"
5+
}

gp-maven-plugin/src/it/t4-basic-download-success/verify.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ try {
2525
println "verifying that download happened successfully"
2626
String location = bldDir + "/it/t4-basic-download-success"
2727
String targetLocation = location + "/target/classes/com/bundle1"
28+
String targetLocation2 = location + "/target/classes/com/bundle2"
2829
def dir = new File(targetLocation)
2930
int filecount = 0
3031
int keycount = 5 // including opening and closing braces which take 1 line each
@@ -40,6 +41,13 @@ try {
4041
}
4142
}
4243
assert filecount == 20
44+
45+
def dir2 = new File(targetLocation2)
46+
dir2.traverse { file ->
47+
if (!file.directory) {
48+
assert !file.name.contains("_en_")
49+
}
50+
}
4351
} catch( Throwable t ) {
4452
t.printStackTrace()
4553
return false

gp-maven-plugin/src/main/java/com/ibm/g11n/pipeline/maven/GPDownloadMojo.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
132132
if (outputSrcLang) {
133133
if (bdlLangs.contains(srcLang)) {
134134
exportLanguageResource(client, bf, srcLang, outDir,
135-
outContentOpt, bundleLayout, langIdStyle, langMap);
135+
outContentOpt, bundleLayout, langIdStyle, langMap, srcLang);
136136
} else {
137137
getLog().warn("The specified source language (" + srcLang
138138
+ ") does not exist in the bundle:" + bundleId);
@@ -142,7 +142,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
142142
for (String tgtLang: tgtLangs) {
143143
if (bdlLangs.contains(tgtLang)) {
144144
exportLanguageResource(client, bf, tgtLang, outDir,
145-
outContentOpt, bundleLayout, langIdStyle, langMap);
145+
outContentOpt, bundleLayout, langIdStyle, langMap, srcLang);
146146
} else {
147147
getLog().warn("The specified target language (" + tgtLang
148148
+ ") does not exist in the bundle:" + bundleId);
@@ -154,16 +154,23 @@ public void execute() throws MojoExecutionException, MojoFailureException {
154154

155155
private void exportLanguageResource(ServiceClient client, SourceBundleFile bf, String language,
156156
File outBaseDir, OutputContentOption outContntOpt, BundleLayout bundleLayout,
157-
LanguageIdStyle langIdStyle, Map<String, String> langMap)
157+
LanguageIdStyle langIdStyle, Map<String, String> langMap, String srcLang)
158158
throws MojoFailureException {
159159
String srcFileName = bf.getFile().getName();
160160
String relPath = bf.getRelativePath();
161-
162161
File outputFile = null;
163162

164163
switch (bundleLayout) {
165164
case LANGUAGE_SUFFIX: {
166165
File dir = (new File(outBaseDir, relPath)).getParentFile();
166+
167+
// truncate source suffix from sourceFile name - BEGIN
168+
int extensionIndex = srcFileName.lastIndexOf('.');
169+
String extension = (extensionIndex > 0) ? srcFileName.substring(extensionIndex) : "";
170+
int srcSuffixIndex = srcFileName.lastIndexOf("_" + getLanguageId(srcLang, langIdStyle, langMap));
171+
srcFileName = (srcSuffixIndex > 0) ? srcFileName.substring(0,srcSuffixIndex) + extension : srcFileName;
172+
// truncate source suffix from sourceFile name - END
173+
167174
int idx = srcFileName.lastIndexOf('.');
168175
String tgtName = null;
169176
if (idx < 0) {

0 commit comments

Comments
 (0)