Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz1002378 - update script to clean up GWT generated unsupported plu…
Browse files Browse the repository at this point in the history
…ral form in properties
  • Loading branch information
Patrick Huang committed Jan 20, 2014
1 parent 9fc8b4a commit af59bfb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
49 changes: 47 additions & 2 deletions zanata-war/src/etc/SyncGWTI18NProperties.groovy
Expand Up @@ -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")
Expand All @@ -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 {
Expand All @@ -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")
}
}
}
}
Expand Up @@ -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);

Expand Down

0 comments on commit af59bfb

Please sign in to comment.