Skip to content

Commit 565dda7

Browse files
author
Yoshito Umaoka
committed
Fixed a merge issue
2 parents 4d855ad + fe56c08 commit 565dda7

3 files changed

Lines changed: 95 additions & 49 deletions

File tree

-5.61 MB
Binary file not shown.

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

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void setOutputDir(File outputDir) {
6464
* Whether this goal overwrites existing bundle file in output directory
6565
* or not. The default value is true.
6666
*/
67-
private boolean overwrite;
67+
private boolean overwrite = true;
6868

6969
public void setOverwrite(boolean overwrite) {
7070
this.overwrite = overwrite;
@@ -236,15 +236,37 @@ private void exportLanguageResource(ServiceClient client, SourceBundleFile bf, S
236236
outputFile.getParentFile().mkdirs();
237237
}
238238

239+
Bundle bundle;
240+
239241
switch (outContntOpt) {
240242
case MERGE_TO_SOURCE:
241-
mergeTranslation(client, bf.getBundleId(), language, bf.getType(), bf.getFile(), outputFile);
243+
bundle = getBundle(client, bf.getBundleId(), language, false, true);
244+
mergeTranslation(bundle, language, bf.getType(), bf.getFile(), outputFile);
242245
break;
246+
243247
case TRANSLATED_WITH_FALLBACK:
244-
exportTranslation(client, bf.getBundleId(), language, bf.getType(), outputFile, true);
248+
bundle = getBundle(client, bf.getBundleId(), language, false, true);
249+
exportTranslation(bundle, language, bf.getType(), outputFile);
245250
break;
251+
246252
case TRANSLATED_ONLY:
247-
exportTranslation(client, bf.getBundleId(), language, bf.getType(), outputFile, false);
253+
bundle = getBundle(client, bf.getBundleId(), language, false, false);
254+
exportTranslation(bundle, language, bf.getType(), outputFile);
255+
break;
256+
257+
case MERGE_REVIEWED_TO_SOURCE:
258+
bundle = getBundle(client, bf.getBundleId(), language, true, true);
259+
mergeTranslation(bundle, language, bf.getType(), bf.getFile(), outputFile);
260+
break;
261+
262+
case REVIEWED_WITH_FALLBACK:
263+
bundle = getBundle(client, bf.getBundleId(), language, true, true);
264+
exportTranslation(bundle, language, bf.getType(), outputFile);
265+
break;
266+
267+
case REVIEWED_ONLY:
268+
bundle = getBundle(client, bf.getBundleId(), language, true, false);
269+
exportTranslation(bundle, language, bf.getType(), outputFile);
248270
break;
249271
}
250272
}
@@ -269,63 +291,61 @@ private String getLanguageId(String gpLanguageTag, LanguageIdStyle langIdStyle,
269291
return languageId;
270292
}
271293

272-
private void mergeTranslation(ServiceClient client, String bundleId, String language,
273-
ResourceType type, File srcFile, File outFile) throws BuildException {
274-
Bundle resBundle = null;
275-
try {
276-
resBundle = getBundle(client, bundleId, language, false);
277-
} catch (ServiceException e) {
278-
throw new BuildException("Globalization Pipeline service error", e);
279-
}
280-
294+
private void mergeTranslation(Bundle bundle, String language, ResourceType type,
295+
File srcFile, File outFile) throws BuildException {
281296
ResourceFilter filter = ResourceFilterFactory.get(type);
282297
try (FileOutputStream fos = new FileOutputStream(outFile);
283298
FileInputStream fis = new FileInputStream(srcFile)) {
284-
filter.merge(fis, fos, language, resBundle);
299+
filter.merge(fis, fos, language, bundle);
285300
} catch (IOException e) {
286301
throw new BuildException("I/O error while merging the translated values to "
287302
+ outFile.getAbsolutePath(), e);
288303
}
289304
}
290305

291-
private void exportTranslation(ServiceClient client, String bundleId, String language,
292-
ResourceType type, File outFile, boolean withFallback) throws BuildException {
293-
Bundle resBundle = null;
294-
try {
295-
resBundle = getBundle(client, bundleId, language, withFallback);
296-
} catch (ServiceException e) {
297-
throw new BuildException("Globalization Pipeline service error", e);
298-
}
299-
306+
private void exportTranslation(Bundle bundle, String language, ResourceType type,
307+
File outFile) throws BuildException {
300308
ResourceFilter filter = ResourceFilterFactory.get(type);
301309
try (FileOutputStream fos = new FileOutputStream(outFile)) {
302-
filter.write(fos, language, resBundle);
310+
filter.write(fos, language, bundle);
303311
} catch (IOException e) {
304312
throw new BuildException("Failed to write the translated resoruce data to "
305313
+ outFile.getAbsolutePath(), e);
306314
}
307315
}
308316

309-
private Bundle getBundle(ServiceClient client,
310-
String bundleId, String language, boolean withFallback) throws ServiceException {
311-
Map<String, ResourceEntryData> resEntries = client.getResourceEntries(bundleId, language);
312-
Collection<ResourceString> resStrings = new LinkedList<>();
313-
for (Entry<String, ResourceEntryData> entry : resEntries.entrySet()) {
314-
String key = entry.getKey();
315-
ResourceEntryData data = entry.getValue();
316-
String resVal = data.getValue();
317-
Integer seqNum = data.getSequenceNumber();
318-
if (resVal == null && withFallback) {
319-
resVal = data.getSourceValue();
320-
}
321-
if (resVal != null) {
322-
ResourceString resString = new ResourceString(key, resVal);
323-
if (seqNum != null) {
324-
resString.setSequenceNumber(seqNum.intValue());
317+
private Bundle getBundle(ServiceClient client, String bundleId, String language,
318+
boolean reviewedOnly, boolean withFallback) throws BuildException {
319+
try {
320+
Map<String, ResourceEntryData> resEntries = client.getResourceEntries(bundleId, language);
321+
Collection<ResourceString> resStrings = new LinkedList<>();
322+
for (Entry<String, ResourceEntryData> entry : resEntries.entrySet()) {
323+
String key = entry.getKey();
324+
ResourceEntryData data = entry.getValue();
325+
String resVal = data.getValue();
326+
Integer seqNum = data.getSequenceNumber();
327+
328+
if (reviewedOnly) {
329+
if (!data.isReviewed()) {
330+
resVal = null;
331+
}
332+
}
333+
334+
if (resVal == null && withFallback) {
335+
resVal = data.getSourceValue();
336+
}
337+
338+
if (resVal != null) {
339+
ResourceString resString = new ResourceString(key, resVal);
340+
if (seqNum != null) {
341+
resString.setSequenceNumber(seqNum.intValue());
342+
}
343+
resStrings.add(resString);
325344
}
326-
resStrings.add(resString);
327345
}
346+
return new Bundle(resStrings, null);
347+
} catch (ServiceException e) {
348+
throw new BuildException("Globalization Pipeline service error", e);
328349
}
329-
return new Bundle(resStrings, null);
330350
}
331351
}

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

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,41 @@
2121
* @author Yoshito Umaoka
2222
*/
2323
public enum OutputContentOption {
24-
// Merges translated resources into source file contents
25-
// if possible. If the output resource format does not support
26-
// this option, TRANSLATION_WITH_FALLBACK is used.
24+
/**
25+
* Merges translated resources into source file contents
26+
* if possible. If the output resource format does not support
27+
* this option, {@link #TRANSLATED_WITH_FALLBACK} is used.
28+
*/
2729
MERGE_TO_SOURCE,
2830

29-
// Exports translated resources. If translation is not available
30-
// for a resource key, the value from the source bundle is used.
31+
/**
32+
* Exports translated resources. If translation is not available
33+
* for a resource key, the value from the source bundle is used.
34+
*/
3135
TRANSLATED_WITH_FALLBACK,
3236

33-
// Exports only translated resources.
34-
TRANSLATED_ONLY
37+
/**
38+
* Exports only translated resources.
39+
*/
40+
TRANSLATED_ONLY,
41+
42+
/**
43+
* Merges translated resources marked as reviewed into source
44+
* file contents if possible. If the output resource format
45+
* does not support this option, {@link #REVIEWED_WITH_FALLBACK}
46+
* is used.
47+
*/
48+
MERGE_REVIEWED_TO_SOURCE,
49+
50+
/**
51+
* Exports translated resources marked as reviewed. If translation
52+
* is not available or, not marked as reviewed, the value from the
53+
* source bundle is used.
54+
*/
55+
REVIEWED_WITH_FALLBACK,
56+
57+
/**
58+
* Exports only translated resources marked as reviewed.
59+
*/
60+
REVIEWED_ONLY
3561
}

0 commit comments

Comments
 (0)