Skip to content

Commit 6224727

Browse files
authored
Merge pull request #48 from yumaoka/rfe-44-reviewed-only
Added new maven plugin output content options
2 parents b7259c6 + 84394ed commit 6224727

3 files changed

Lines changed: 104 additions & 51 deletions

File tree

gp-maven-plugin.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ versions in parallel language directories.
308308
localized version will use the same file name with source, but placed in a directory
309309
for the language. `<languageIdStyle>` specifies the style of language ID used for
310310
file/path name. **BCP47** specifies the BCP 47 language tag. In this case, '-' (Hyphen)
311-
is used for subtag separtors, such as 'zh-Hans'.
311+
is used for subtag separators, such as 'zh-Hans'.
312312

313313
With this example, if you have English JSON resource file at `src/main/webapp/res/en/MyStrings.json`,
314314
French version is generated at `target/MyApp/res/fr/MyStrings.json`, and Simplified Chinese
@@ -495,6 +495,13 @@ resource strings. This option might not be implemented by some format types. In
495495
When translated string value is not available, the value in the source language is used.
496496
* **TRANSLATED_ONLY** Emits only resource strings (with a simple header if applicable).
497497
When translated string value is not available, do not include the key in the output.
498+
* **MERGE_REVIEWED_TO_SOURCE** Duplicate the contents of the source bundle and replaces only
499+
translated resource strings marked as reviewed. This option might not be implemented by some
500+
format types. In this case, **REVIEWED_WITH_FALLBACK** is used instead.
501+
* **REVIEWED_WITH_FALLBACK** Emits only resource strings marked as reviewed. When translated string
502+
value is not available, or not marked as reviewed, the value in the source language is used.
503+
* **REVIEWED_ONLY** Emits only resource strings marked as reviewed. When translated string value
504+
is not available, or translated not marked as reviewed, do not include the key in the output.
498505

499506
The default value is **MERGE_TO_SOURCE**.
500507

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

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright IBM Corp. 2016
2+
* Copyright IBM Corp. 2016, 2017
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -211,15 +211,37 @@ private void exportLanguageResource(ServiceClient client, SourceBundleFile bf, S
211211
outputFile.getParentFile().mkdirs();
212212
}
213213

214+
Bundle bundle;
215+
214216
switch (outContntOpt) {
215217
case MERGE_TO_SOURCE:
216-
mergeTranslation(client, bf.getBundleId(), language, bf.getType(), bf.getFile(), outputFile);
218+
bundle = getBundle(client, bf.getBundleId(), language, false, true);
219+
mergeTranslation(bundle, language, bf.getType(), bf.getFile(), outputFile);
217220
break;
221+
218222
case TRANSLATED_WITH_FALLBACK:
219-
exportTranslation(client, bf.getBundleId(), language, bf.getType(), outputFile, true);
223+
bundle = getBundle(client, bf.getBundleId(), language, false, true);
224+
exportTranslation(bundle, language, bf.getType(), outputFile);
220225
break;
226+
221227
case TRANSLATED_ONLY:
222-
exportTranslation(client, bf.getBundleId(), language, bf.getType(), outputFile, false);
228+
bundle = getBundle(client, bf.getBundleId(), language, false, false);
229+
exportTranslation(bundle, language, bf.getType(), outputFile);
230+
break;
231+
232+
case MERGE_REVIEWED_TO_SOURCE:
233+
bundle = getBundle(client, bf.getBundleId(), language, true, true);
234+
mergeTranslation(bundle, language, bf.getType(), bf.getFile(), outputFile);
235+
break;
236+
237+
case REVIEWED_WITH_FALLBACK:
238+
bundle = getBundle(client, bf.getBundleId(), language, true, true);
239+
exportTranslation(bundle, language, bf.getType(), outputFile);
240+
break;
241+
242+
case REVIEWED_ONLY:
243+
bundle = getBundle(client, bf.getBundleId(), language, true, false);
244+
exportTranslation(bundle, language, bf.getType(), outputFile);
223245
break;
224246
}
225247
}
@@ -244,63 +266,61 @@ private String getLanguageId(String gpLanguageTag, LanguageIdStyle langIdStyle,
244266
return languageId;
245267
}
246268

247-
private void mergeTranslation(ServiceClient client, String bundleId, String language,
248-
ResourceType type, File srcFile, File outFile) throws MojoFailureException {
249-
Bundle resBundle = null;
250-
try {
251-
resBundle = getBundle(client, bundleId, language, false);
252-
} catch (ServiceException e) {
253-
throw new MojoFailureException("Globalization Pipeline service error", e);
254-
}
255-
269+
private void mergeTranslation(Bundle bundle, String language, ResourceType type,
270+
File srcFile, File outFile) throws MojoFailureException {
256271
ResourceFilter filter = ResourceFilterFactory.get(type);
257272
try (FileOutputStream fos = new FileOutputStream(outFile);
258273
FileInputStream fis = new FileInputStream(srcFile)) {
259-
filter.merge(fis, fos, language, resBundle);
274+
filter.merge(fis, fos, language, bundle);
260275
} catch (IOException e) {
261276
throw new MojoFailureException("I/O error while merging the translated values to "
262277
+ outFile.getAbsolutePath(), e);
263278
}
264279
}
265280

266-
private void exportTranslation(ServiceClient client, String bundleId, String language,
267-
ResourceType type, File outFile, boolean withFallback) throws MojoFailureException {
268-
Bundle resBundle = null;
269-
try {
270-
resBundle = getBundle(client, bundleId, language, withFallback);
271-
} catch (ServiceException e) {
272-
throw new MojoFailureException("Globalization Pipeline service error", e);
273-
}
274-
281+
private void exportTranslation(Bundle bundle, String language, ResourceType type,
282+
File outFile) throws MojoFailureException {
275283
ResourceFilter filter = ResourceFilterFactory.get(type);
276284
try (FileOutputStream fos = new FileOutputStream(outFile)) {
277-
filter.write(fos, language, resBundle);
285+
filter.write(fos, language, bundle);
278286
} catch (IOException e) {
279287
throw new MojoFailureException("Failed to write the translated resoruce data to "
280288
+ outFile.getAbsolutePath(), e);
281289
}
282290
}
283291

284-
private Bundle getBundle(ServiceClient client,
285-
String bundleId, String language, boolean withFallback) throws ServiceException {
286-
Map<String, ResourceEntryData> resEntries = client.getResourceEntries(bundleId, language);
287-
Collection<ResourceString> resStrings = new LinkedList<>();
288-
for (Entry<String, ResourceEntryData> entry : resEntries.entrySet()) {
289-
String key = entry.getKey();
290-
ResourceEntryData data = entry.getValue();
291-
String resVal = data.getValue();
292-
Integer seqNum = data.getSequenceNumber();
293-
if (resVal == null && withFallback) {
294-
resVal = data.getSourceValue();
295-
}
296-
if (resVal != null) {
297-
ResourceString resString = new ResourceString(key, resVal);
298-
if (seqNum != null) {
299-
resString.setSequenceNumber(seqNum.intValue());
292+
private Bundle getBundle(ServiceClient client, String bundleId, String language,
293+
boolean reviewedOnly, boolean withFallback) throws MojoFailureException {
294+
try {
295+
Map<String, ResourceEntryData> resEntries = client.getResourceEntries(bundleId, language);
296+
Collection<ResourceString> resStrings = new LinkedList<>();
297+
for (Entry<String, ResourceEntryData> entry : resEntries.entrySet()) {
298+
String key = entry.getKey();
299+
ResourceEntryData data = entry.getValue();
300+
String resVal = data.getValue();
301+
Integer seqNum = data.getSequenceNumber();
302+
303+
if (reviewedOnly) {
304+
if (!data.isReviewed()) {
305+
resVal = null;
306+
}
307+
}
308+
309+
if (resVal == null && withFallback) {
310+
resVal = data.getSourceValue();
311+
}
312+
313+
if (resVal != null) {
314+
ResourceString resString = new ResourceString(key, resVal);
315+
if (seqNum != null) {
316+
resString.setSequenceNumber(seqNum.intValue());
317+
}
318+
resStrings.add(resString);
300319
}
301-
resStrings.add(resString);
302320
}
321+
return new Bundle(resStrings, null);
322+
} catch (ServiceException e) {
323+
throw new MojoFailureException("Globalization Pipeline service error", e);
303324
}
304-
return new Bundle(resStrings, null);
305325
}
306326
}

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

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright IBM Corp. 2016
2+
* Copyright IBM Corp. 2016, 2017
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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)