This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository i18n. See http://git.nuiton.org/i18n.git commit c620165255300efd898a95f09bb8c4f4e393e5d3 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Jul 26 17:36:25 2014 +0200 refs #3356 improve merge mojo + add mini doc --- .../plugin/bundle/csv/MergeBackCsvBundleMojo.java | 26 ++++++++++++++++++- i18n-maven-plugin/src/site/apt/index.apt | 6 +++++ i18n-maven-plugin/src/site/apt/usages.apt | 30 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/csv/MergeBackCsvBundleMojo.java b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/csv/MergeBackCsvBundleMojo.java index 3272a02..40b5a5f 100644 --- a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/csv/MergeBackCsvBundleMojo.java +++ b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/bundle/csv/MergeBackCsvBundleMojo.java @@ -5,6 +5,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.nuiton.csv.Import; import org.nuiton.io.SortedProperties; @@ -29,6 +30,16 @@ import java.util.Locale; requiresDependencyResolution = ResolutionScope.RUNTIME) public class MergeBackCsvBundleMojo extends AbstractCsvBundleMojo { + /** + * To accept to add new keys in the original i18n bundle. + * <p/> + * The option is {@code false} by default, since merging operation should not add any new keys. + * + * @since 3.3 + */ + @Parameter(property = "i18n.mergeNewKeys", defaultValue = "false") + protected boolean mergeNewKeys; + @Override protected void doAction() throws Exception { @@ -40,6 +51,8 @@ public class MergeBackCsvBundleMojo extends AbstractCsvBundleMojo { } + // load i18n csv file + LinkedList<I18nBundleModelRow> rows; I18nBundleModel importModel = new I18nBundleModel(bundleCsvSeparator, locales); @@ -55,6 +68,8 @@ public class MergeBackCsvBundleMojo extends AbstractCsvBundleMojo { IOUtils.closeQuietly(inputStream); } + // start the merge + for (Locale locale : locales) { File bundleFile = getI18nFile(src, @@ -69,12 +84,21 @@ public class MergeBackCsvBundleMojo extends AbstractCsvBundleMojo { // push back values from csv file for (I18nBundleModelRow row : rows) { - properties.put(row.getKey(), row.getLocaleValue(locale)); + + String key = row.getKey(); + + boolean keyIsPresent = properties.containsKey(key); + if (mergeNewKeys || keyIsPresent) { + + properties.put(key, row.getLocaleValue(locale)); + } + } if (!isSilent()) { getLog().info(String.format("Merge locale bundle %s in %s", locale, bundleFile)); } + properties.store(bundleFile); } diff --git a/i18n-maven-plugin/src/site/apt/index.apt b/i18n-maven-plugin/src/site/apt/index.apt index 8d3ad9c..f546f61 100644 --- a/i18n-maven-plugin/src/site/apt/index.apt +++ b/i18n-maven-plugin/src/site/apt/index.apt @@ -54,6 +54,12 @@ Goals Overview * {{{./tapestry-bundle-mojo.html} i18n:tapestry-bundle}} generate unique i18n bundle for tapestry application. + * {{{./generate-csv-bunle-mojo.html} i18n:help}} generate a single csv file with i18n sentences for some locales. + + * {{{./split-csv-bunle-mojo.html} i18n:help}} split back a csv i18n file into i18n bundle files (one file for each locale) + + * {{{./merge-back-csv-bunle-mojo.html} i18n:help}} merge back a csv i18n file into i18n bundle files + * {{{./help-mojo.html} i18n:help}} display help. Usage diff --git a/i18n-maven-plugin/src/site/apt/usages.apt b/i18n-maven-plugin/src/site/apt/usages.apt index a39612d..ffbf520 100644 --- a/i18n-maven-plugin/src/site/apt/usages.apt +++ b/i18n-maven-plugin/src/site/apt/usages.apt @@ -231,6 +231,36 @@ mymodule/ </plugin> ----------------------------------------------------------------------------- +Csv Bundle (since 3.3) + +* Generate a csv bundle + + You can generate a single csv file with the bundles via the generate-csv-file (after a bundle invocation). + +----------------------------------------------------------------------------- +<plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>i18n-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>bundle</goal> + <goal>generate-csv-file</goal> + </goals> + </execution> + </executions> +</plugin> +----------------------------------------------------------------------------- + + You can then give the csv file to people to edit it. + +* Split or merge a csv bundle + + Having them the csv file filled by people you can then split it back to some i18n bundle files with + the split-csv-file mojo. + + Event better you can merge it back to the i18n files of a module using the <<merge-back-csv-file>> mojo. + And there is more for you! There is some other interesting properties in the plugin, for example it is -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.