Geertjan's Blog

  • March 2, 2011

i18nchecker (Part 2)

Geertjan Wielenga
Product Manager
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}"/>
<!-- 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 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"/>

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.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.