i18nchecker (Part 2)

In part 1, yesterday, you were introduced to Tim & Petr's i18nchecker. Let's now learn how to use it without the source files. I.e., we'll get all the required JARs, add some targets to our build script, and then use the tool. That's a more natural way to do it, instead of downloading the sources, copying our own app into the playground, and then using the targets from there.

So, go to the site, download the JARs you see highlighted below, and put them into the root directory of you app (as an example, I'm using the NetBeans Platform Paint Application), exactly as shown in the screenshot here, of the Files window in NetBeans IDE 7.0 Beta 2:

Note that we also have a 'translations' folder in our root directory, which is where we'll put our translated csv files. Before that, we'll have the original csv file generated into the 'build' folder, as you can see above.

And here are our tweaked targets:

<target name="i18n-consistency-check" description="Verification of localized strings in source code" depends="build">
    <property file="nbproject/private/private.properties"/>
    <property name="i18n.modulefilter" value=""/>
    <echo>I18N Consistency Check - use modulefilter property if you want to see errors only from one module</echo>
    <taskdef classname="org.i18nchecker.I18nChecker" name="i18nConsistencyCheck" classpath="ant.jar:antlr-runtime-3.2.jar:i18nchecker.jar"/>
    <i18nConsistencyCheck srcdir=".." topdirs="PaintApp" modulefilter="${i18n.modulefilter}"/>
</target>

<!-- TODO: improve following tasks - reuse taskdef etc. -->
<target name="i18n-prepare-japanese" description="Prepare CSV file for translation to Japanese">
    <taskdef classname="org.i18nchecker.I18nChecker" name="i18nConsistencyCheck" classpath="ant.jar:antlr-runtime-3.2.jar:i18nchecker.jar"/>
    <mkdir dir="build/i18n"/>
    <i18nConsistencyCheck srcdir=".." topdirs="PaintApp" language="ja" exportto="build/i18n/japanese.csv"/>
</target>

<target name="i18n-apply-japanese" description="Apply Japanese translation to projects resource bundles">
    <taskdef classname="org.i18nchecker.I18nChecker" name="i18nConsistencyCheck" classpath="ant.jar:antlr-runtime-3.2.jar:i18nchecker.jar:SuperCSV-1.52.jar"/>
    <i18nConsistencyCheck srcdir=".." topdirs="PaintApp" language="ja" importfrom="translations/japanese.csv"/>
</target>

That's all. Now, when you run the first target, the app is built and the consistency check is done, with messages in the IDE's Output window. The next target generates the csv file from the bundles in the application, while the final target integrates a translated csv file back into the app (i.e., it creates new bundle files in all the modules where the original bundle files were found, e.g., it creates "Bundle_ja.properties" in the modules, and populates those files with the translations from the csv file).

The above is, of course, not relevant for NetBeans Platform applications only. Any Java applications with bundle files in 'src' root structures can benefit from this cool tool too.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today