Skip to content

Commit d1222ec

Browse files
authored
Merge pull request #87 from yumaoka/rfe-85-ant
Follow up fixes for PR#84 and #86
2 parents 5c902a6 + 2f33a74 commit d1222ec

3 files changed

Lines changed: 51 additions & 26 deletions

File tree

gp-ant-task/src/main/java/com/ibm/g11n/pipeline/ant/GPBaseTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private String pathToBundleId(ResourceType type, String path) {
240240
String pkgName = parent == null ? "" :
241241
parent.getPath().replace(File.separatorChar, '.');
242242

243-
String fileName = f.getName();
243+
String fileName = f.getName().replaceAll(" ", "_");
244244
if (type == ResourceType.JAVA) {
245245
int dotIdx = fileName.indexOf('.');
246246
if (dotIdx >= 0) {

gp-ant-task/src/main/java/com/ibm/g11n/pipeline/ant/GPDownloadTask.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void execute() throws BuildException {
145145
if (outputSrcLang) {
146146
if (bdlLangs.contains(srcLang)) {
147147
exportLanguageResource(client, bf, srcLang, outDir,
148-
outContentOpt, bundleLayout, langIdStyle, langMap);
148+
outContentOpt, bundleLayout, langIdStyle, langMap, srcLang);
149149
} else {
150150
getProject().log("The specified source language (" + srcLang
151151
+ ") does not exist in the bundle:" + bundleId, Project.MSG_WARN);
@@ -155,7 +155,7 @@ public void execute() throws BuildException {
155155
for (String tgtLang: tgtLangs) {
156156
if (bdlLangs.contains(tgtLang)) {
157157
exportLanguageResource(client, bf, tgtLang, outDir,
158-
outContentOpt, bundleLayout, langIdStyle, langMap);
158+
outContentOpt, bundleLayout, langIdStyle, langMap, srcLang);
159159
} else {
160160
getProject().log("The specified target language (" + tgtLang
161161
+ ") does not exist in the bundle:" + bundleId, Project.MSG_WARN);
@@ -175,11 +175,12 @@ public void execute() throws BuildException {
175175
* @param bundleLayout
176176
* @param langIdStyle
177177
* @param langMap
178+
* @param srcLang
178179
* @throws BuildException
179180
*/
180181
private void exportLanguageResource(ServiceClient client, SourceBundleFile bf, String language,
181182
File outBaseDir, OutputContentOption outContntOpt, BundleLayout bundleLayout,
182-
LanguageIdStyle langIdStyle, Map<String, String> langMap)
183+
LanguageIdStyle langIdStyle, Map<String, String> langMap, String srcLang)
183184
throws BuildException {
184185
String srcFileName = bf.getFile().getName();
185186
String relPath = bf.getRelativePath();
@@ -189,14 +190,30 @@ private void exportLanguageResource(ServiceClient client, SourceBundleFile bf, S
189190
switch (bundleLayout) {
190191
case LANGUAGE_SUFFIX: {
191192
File dir = (new File(outBaseDir, relPath)).getParentFile();
192-
int idx = srcFileName.lastIndexOf('.');
193-
String tgtName = null;
194-
if (idx < 0) {
195-
tgtName = srcFileName + "_" + getLanguageId(language, langIdStyle, langMap);
196-
} else {
197-
tgtName = srcFileName.substring(0, idx) + "_" + getLanguageId(language, langIdStyle, langMap)
198-
+ srcFileName.substring(idx);
193+
194+
String tgtName = srcFileName;
195+
// Compose file name if the output language is not the source language
196+
if (!language.equals(srcLang)) {
197+
String baseName = srcFileName;
198+
String extension = "";
199+
int extensionIndex = srcFileName.lastIndexOf('.');
200+
if (extensionIndex > 0) {
201+
baseName = srcFileName.substring(0, extensionIndex);
202+
extension = srcFileName.substring(extensionIndex);
203+
}
204+
205+
// checks if the source file's base name (without extension) ends with
206+
// source language code suffix, e.g. foo_en => foo
207+
String srcLangSuffix = "_" + getLanguageId(srcLang, langIdStyle, langMap);
208+
if (baseName.endsWith(srcLangSuffix)) {
209+
// truncates source the source language suffix from base name
210+
baseName = baseName.substring(0, baseName.length() - srcLangSuffix.length());
211+
}
212+
213+
// append target language suffix to the base name, e.g. foo => foo_de
214+
tgtName = baseName + "_" + getLanguageId(language, langIdStyle, langMap) + extension;
199215
}
216+
200217
outputFile = new File(dir, tgtName);
201218
break;
202219
}

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,30 @@ private void exportLanguageResource(ServiceClient client, SourceBundleFile bf, S
163163
switch (bundleLayout) {
164164
case LANGUAGE_SUFFIX: {
165165
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-
174-
int idx = srcFileName.lastIndexOf('.');
175-
String tgtName = null;
176-
if (idx < 0) {
177-
tgtName = srcFileName + "_" + getLanguageId(language, langIdStyle, langMap);
178-
} else {
179-
tgtName = srcFileName.substring(0, idx) + "_" + getLanguageId(language, langIdStyle, langMap)
180-
+ srcFileName.substring(idx);
166+
167+
String tgtName = srcFileName;
168+
// Compose file name if the output language is not the source language
169+
if (!language.equals(srcLang)) {
170+
String baseName = srcFileName;
171+
String extension = "";
172+
int extensionIndex = srcFileName.lastIndexOf('.');
173+
if (extensionIndex > 0) {
174+
baseName = srcFileName.substring(0, extensionIndex);
175+
extension = srcFileName.substring(extensionIndex);
176+
}
177+
178+
// checks if the source file's base name (without extension) ends with
179+
// source language code suffix, e.g. foo_en => foo
180+
String srcLangSuffix = "_" + getLanguageId(srcLang, langIdStyle, langMap);
181+
if (baseName.endsWith(srcLangSuffix)) {
182+
// truncates source the source language suffix from base name
183+
baseName = baseName.substring(0, baseName.length() - srcLangSuffix.length());
184+
}
185+
186+
// append target language suffix to the base name, e.g. foo => foo_de
187+
tgtName = baseName + "_" + getLanguageId(language, langIdStyle, langMap) + extension;
181188
}
189+
182190
outputFile = new File(dir, tgtName);
183191
break;
184192
}

0 commit comments

Comments
 (0)