From af59bfbfea7811b495761cd1322d8bc0d3205dce Mon Sep 17 00:00:00 2001 From: Patrick Huang Date: Mon, 13 Jan 2014 16:54:23 +1000 Subject: [PATCH] rhbz1002378 - update script to clean up GWT generated unsupported plural form in properties --- .../src/etc/SyncGWTI18NProperties.groovy | 49 ++++++++++++++++++- .../client/resources/WebTransMessages.java | 10 ++-- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/zanata-war/src/etc/SyncGWTI18NProperties.groovy b/zanata-war/src/etc/SyncGWTI18NProperties.groovy index 062acbb286..3c8955b3af 100644 --- a/zanata-war/src/etc/SyncGWTI18NProperties.groovy +++ b/zanata-war/src/etc/SyncGWTI18NProperties.groovy @@ -20,7 +20,7 @@ if (!properties) { log.info "no properties found. quit." return } -// scrip off the file name part to get packge name +// scrip off the file name part to get package name def packageName = properties[0].name.replaceAll(/\.\w+\.properties/, "") def packagePath = packageName.replaceAll(/\./, "/") def destDir = new File(pom.basedir.absolutePath + "/src/main/resources/$packagePath") @@ -36,7 +36,6 @@ properties.each { log.debug " * found source: $it.name" // we always copy over source file log.debug " copy over to: $destFile" - // copy the file with _default to make GWT happy Files.copy(it, destFile) sourceCount++ } else { @@ -52,3 +51,49 @@ properties.each { log.info "Copied $sourceCount source(s) and $targetCount target(s) in $baseDir" log.info "===== Synchronize GWT generated properties files =====" + +// below procedure is to fix GWT's bizarre behavior. +// if we have properties files on classpath (i.e. compile with extra already), +// the second time GWT compiler produces properties file will output plural forms in properties but some of them are empty. +// It will be empty if: +// 1. the required plural form for that language is not defined in java interface. i.e. in Ukranian you ought to have "one", "few", "other" defined in @AlternateMessage. +// see com.google.gwt.i18n.client.impl.plurals.DefaultRule_x1_x234_n +// 2. in java interface it uses complex plural combination. i.e. having multiple @PluralCount in parameters. +// see org.zanata.webtrans.client.resources.WebTransMessages.showingResultsForProjectWideSearch +// First one won't cause any trouble. We can ignore it. +// Second one may not be fixable. The GWT doc says the plural form is still a work in progress. I don't know how it works either. +// We can either add extra plural count in the [] i.e. turn [one] to [one|one]. But Zanata doesn't support mismatch source and target. +// So I removing those extra plural entries which allows GWT to compile again (with a warning). +// see https://github.com/zanata/zanata-server/wiki/Localize-Zanata for more detail. +File pomBase = pom.basedir +baseDir = new File(pomBase.absolutePath + "/src/main/resources/org/zanata/webtrans/client/resources/") + +assert baseDir.isDirectory() + +def filter = { + // we won't touch source properties + it.name.endsWith(".properties") && !it.name.endsWith("_default.properties") +} as FileFilter +properties = baseDir.listFiles(filter) + +def ln = System.getProperty("line.separator") + +properties.each { + def lines = it.readLines("UTF-8") + boolean touched = false + lines.eachWithIndex { line, index -> + if (line.matches(/.+=$/)) { + log.info("found and removed empty plural entry: {}", line) + lines.set(index, "") + touched = true + } + } + if (touched) { + log.info("processed {}", it.name) + it.withPrintWriter("UTF-8") { writer -> + lines.each { + writer.append("$it$ln") + } + } + } +} diff --git a/zanata-war/src/main/java/org/zanata/webtrans/client/resources/WebTransMessages.java b/zanata-war/src/main/java/org/zanata/webtrans/client/resources/WebTransMessages.java index bdd546df93..bbe34cb786 100644 --- a/zanata-war/src/main/java/org/zanata/webtrans/client/resources/WebTransMessages.java +++ b/zanata-war/src/main/java/org/zanata/webtrans/client/resources/WebTransMessages.java @@ -124,10 +124,12 @@ String statusBarPercentageHrs(String approved, String remainingHours, String searchFoundResultsInDocuments(@PluralCount int numDocs); @DefaultMessage("Showing results for search \"{0}\" ({1} text flows in {2} documents)") - @AlternateMessage({ "one|one", - "Showing results for search \"{0}\" (1 text flow in 1 document)", - "other|one", - "Showing results for search \"{0}\" ({1} text flows in 1 document)" }) + // @formatter:off + @AlternateMessage({ + "one|one", "Showing results for search \"{0}\" (1 text flow in 1 document)", + "other|one", "Showing results for search \"{0}\" ({1} text flows in 1 document)" + }) + // @formatter:on String showingResultsForProjectWideSearch(String searchString, @PluralCount int textFlows, @PluralCount int documents);