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

Commit

Permalink
enable localization of gwt resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Jan 6, 2014
1 parent e6b7e7d commit 3b49f37
Show file tree
Hide file tree
Showing 44 changed files with 4,230 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pom.xml
Expand Up @@ -727,6 +727,14 @@
<artifactId>jcabi-mysql-maven-plugin</artifactId>
<version>0.4</version>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<configuration>
<providerSelection>2.0</providerSelection>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
1 change: 1 addition & 0 deletions zanata-war/.gitignore
@@ -0,0 +1 @@
.zanata-cache
71 changes: 71 additions & 0 deletions zanata-war/pom.xml
Expand Up @@ -418,6 +418,19 @@
</configuration>
</plugin>

<plugin>
<!-- server pom has same plugin definition with different includes -->
<groupId>org.zanata</groupId>
<configuration>
<srcDir>.</srcDir>
<transDir>.</transDir>
<includes>src/main/resources/org/zanata/webtrans/client/resources/*.properties</includes>
<excludes>src/main/resources/org/zanata/webtrans/client/resources/*_default.properties</excludes>
</configuration>
<artifactId>zanata-maven-plugin</artifactId>
<version>3.3.0-SNAPSHOT</version>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
Expand Down Expand Up @@ -1031,6 +1044,64 @@

</profile>

<profile>
<id>gwt-i18n</id>
<activation>
<property>
<name>gwt-i18n</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-i18n</id>
<goals>
<goal>compile</goal>
</goals>
<!--here we bind it to generate-test-resource because we want it to happen before the real compile(prepare-package) and able to do its job -->
<phase>generate-test-resources</phase>
<configuration>
<module>org.zanata.webtrans.ApplicationI18n</module>
<extra>${project.build.directory}/gwt-extra</extra>
<extraParam>true</extraParam>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<configuration>
<!-- the groovy.script will be given by command line arg -->
<!-- at the moment it's used in zanata.xml as command hook -->
<source>${pom.basedir}/src/etc/${groovy.script}</source>
</configuration>
<executions>
<execution>
<phase>generate-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<classpath>
<element>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</element>
</classpath>
<source>${pom.basedir}/src/etc/SyncGWTI18NProperties.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>

<dependencies>
Expand Down
29 changes: 29 additions & 0 deletions zanata-war/src/etc/CopyGWTDefaultProperties.groovy
@@ -0,0 +1,29 @@
import com.google.common.io.Files

// This script will copy GWT generated *_default.properties source file to
// follow java convention. i.e. without the _default in file name.
// It's used in zanata.xml as command hook
File pomBase = pom.basedir
def baseDir = new File(pomBase.absolutePath + "/src/main/resources/org/zanata/webtrans/client/resources/")

assert baseDir.isDirectory()

def nameFilter = { dir, name ->
name.endsWith("_default.properties")
} as FilenameFilter

def properties = baseDir.listFiles(nameFilter)


if (!properties) {
log.info "no *_default.properties found. quit."
return
}

properties.each {
// we need a no locale file name for java properties file convention
def noLocaleFileName = it.name.replace("_default", "")
def noLocaleDestFile = new File(baseDir, noLocaleFileName)
log.debug " copy $it.name to: $noLocaleDestFile"
Files.copy(it, noLocaleDestFile)
}
19 changes: 19 additions & 0 deletions zanata-war/src/etc/RemoveJavaDefaultProperties.groovy
@@ -0,0 +1,19 @@
// This script will remove java default locale properties file so that GWT can compile.
// GWT only expect *_default.properties as default locale file.
// It's used in zanata.xml as command hook

File pomBase = pom.basedir
def baseDir = new File(pomBase.absolutePath + "/src/main/resources/org/zanata/webtrans/client/resources/")

assert baseDir.isDirectory()

// find properties file without underscore
def nameFilter = { dir, name ->
!name.contains("_")
} as FilenameFilter

def properties = baseDir.listFiles(nameFilter)

properties.each {
it.delete()
}
54 changes: 54 additions & 0 deletions zanata-war/src/etc/SyncGWTI18NProperties.groovy
@@ -0,0 +1,54 @@
import com.google.common.io.Files

// This script will be executed by gmaven plugin.
// Although gmaven supports inline scripting in pom, it will escape / in the
// regex and the script therefore won't work.
log.info "===== Synchronize GWT generated properties files ====="

def baseDir = new File(project.build.directory + "/gwt-extra/webtrans")

assert baseDir.isDirectory()

def nameFilter = { dir, name ->
name.endsWith(".properties")
} as FilenameFilter

def properties = baseDir.listFiles(nameFilter)


if (!properties) {
log.info "no properties found. quit."
return
}
// scrip off the file name part to get packge name
def packageName = properties[0].name.replaceAll(/\.\w+\.properties/, "")
def packagePath = packageName.replaceAll(/\./, "/")
def destDir = new File(pom.basedir.absolutePath + "/src/main/resources/$packagePath")
destDir.mkdirs()

int sourceCount = 0
int targetCount = 0

properties.each {
def fileName = (it.name - "$packageName.")
def destFile = new File(destDir, fileName)
if (it.name.endsWith("_default.properties")) {
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 {
log.debug " * found target: $it.name"
// we ALWAYS copy generated target skeleton to make sure target is in sync if source has changed.
// It rely on zanata's merge auto feature.
// Merge type import will override everything!!
log.debug " copy over to :$destFile"
Files.copy(it, destFile);
targetCount++
}
}

log.info "Copied $sourceCount source(s) and $targetCount target(s) in $baseDir"
log.info "===== Synchronize GWT generated properties files ====="
Expand Up @@ -49,6 +49,8 @@
<source path="shared" />

<inherits name="com.google.gwt.i18n.I18N" />
<extend-property name="locale" values="en,qc" />
<!-- if we want to include new locale in our app, add new extend-property value and then add to ApplicationI18n.gwt.xml-->
<!-- at the moment we have included locales in faces-config.xml -->
<extend-property name="locale" values="en,ja,zh_Hant_TW,uk,qc" />
<set-property-fallback name="locale" value="en" />
</module>
@@ -0,0 +1,13 @@
<!--
set-property-fallback is missing from the DTD:
<!DOCTYPE module PUBLIC "//gwt-module/" "http://google-web-toolkit.googlecode.com/svn/tags/2.0.3/distro-source/core/src/gwt-module.dtd">
-->
<module rename-to="webtrans">
<inherits name="org.zanata.webtrans.Application" />
<set-property name="user.agent" value="safari" />
<extend-property name="log_level" values="DEBUG" />
<set-property name="log_level" value="DEBUG" />

<!-- add locales to generate different properties template-->
<set-property name="locale" value="default,en,ja,zh_Hant_TW,uk" />
</module>
@@ -0,0 +1,34 @@
# Generated from org.zanata.webtrans.client.resources.EnumMessages
# for locale default

approvedStatus=Translated

contentStateApproved=Approved

contentStateFuzzy=Fuzzy

contentStateRejected=Rejected

contentStateTranslated=Translated

contentStateUnsaved=Unsaved

contentStateUntranslated=Untranslated

downgradeToFuzzy=Copy as Fuzzy

ignoreDifference=Next Condition

nextDraft=Next Fuzzy or Rejected

nextIncomplete=Next Fuzzy/Rejected/Untranslated

nextUntranslated=Next Untranslated

rejectMerge=Don''t Copy

searchTypeExact=Phrase

searchTypeFuzzy=Fuzzy

searchTypeRaw=Lucene
@@ -0,0 +1,34 @@
# Generated from org.zanata.webtrans.client.resources.EnumMessages
# for locale en

approvedStatus=Translated

contentStateApproved=Approved

contentStateFuzzy=Fuzzy

contentStateRejected=Rejected

contentStateTranslated=Translated

contentStateUnsaved=Unsaved

contentStateUntranslated=Untranslated

downgradeToFuzzy=Copy as Fuzzy

ignoreDifference=Next Condition

nextDraft=Next Fuzzy or Rejected

nextIncomplete=Next Fuzzy/Rejected/Untranslated

nextUntranslated=Next Untranslated

rejectMerge=Don''t Copy

searchTypeExact=Phrase

searchTypeFuzzy=Fuzzy

searchTypeRaw=Lucene
@@ -0,0 +1,34 @@
# Generated from org.zanata.webtrans.client.resources.EnumMessages
# for locale ja

approvedStatus=Translated

contentStateApproved=Approved

contentStateFuzzy=Fuzzy

contentStateRejected=Rejected

contentStateTranslated=Translated

contentStateUnsaved=Unsaved

contentStateUntranslated=Untranslated

downgradeToFuzzy=Copy as Fuzzy

ignoreDifference=Next Condition

nextDraft=Next Fuzzy or Rejected

nextIncomplete=Next Fuzzy/Rejected/Untranslated

nextUntranslated=Next Untranslated

rejectMerge=Don''t Copy

searchTypeExact=Phrase

searchTypeFuzzy=Fuzzy

searchTypeRaw=Lucene
@@ -0,0 +1,34 @@
# Generated from org.zanata.webtrans.client.resources.EnumMessages
# for locale uk

approvedStatus=Translated

contentStateApproved=Approved

contentStateFuzzy=Fuzzy

contentStateRejected=Rejected

contentStateTranslated=Translated

contentStateUnsaved=Unsaved

contentStateUntranslated=Untranslated

downgradeToFuzzy=Copy as Fuzzy

ignoreDifference=Next Condition

nextDraft=Next Fuzzy or Rejected

nextIncomplete=Next Fuzzy/Rejected/Untranslated

nextUntranslated=Next Untranslated

rejectMerge=Don''t Copy

searchTypeExact=Phrase

searchTypeFuzzy=Fuzzy

searchTypeRaw=Lucene

0 comments on commit 3b49f37

Please sign in to comment.