Index Changes
This is version 1. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]

i18n Ant Task

What is it?

An Ant task which generates a message bundle properties file directly from compiled code. No more manual coordination of message keys specified in the code with their corresponding messages in a separate file! This utility allows developers to insert user and/or logging messages directly into the code without maintaining a separate bundle file.

How to use it?

There are just a few simple additions to your project's POM to use this utility:
1. Add a placeholder to execute Ant tasks. More information can be found here.
<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>${project.artifactId}-plugin-description</id>
            <phase>process-classes</phase>
            <goals><goal>run</goal></goals>
            <configuration>
                <tasks>
		    <!-- 	ADD YOUR ANT TASKS HERE		-->
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>
2. Add a dependency on the Hulp i18n Ant task library.
    <dependency>
        <groupId>net.java.hulp.i18ntask</groupId>
        <artifactId>net.java.hulp.i18ntask</artifactId>
        <version>2.1-SNAPSHOT</version>
    </dependency>
3. Add the following Ant tasks:
    <!-- define the i18n task -->
    <taskdef name="i18n" classname="net.java.hulp.i18n.buildtools.I18NTask">
        <classpath>
            <pathelement location="${maven.repo.local}/net/java/hulp/i18ntask/net.java.hulp.i18ntask/2.1-SNAPSHOT/net.java.hulp.i18ntask-2.1-SNAPSHOT.jar"/>
        </classpath>
    </taskdef>
    <!-- call the i18n task -->
    <i18n dir="${project.build.outputDirectory}" 
          file="${project.build.sourceDirectory}/com/sun/jbi/engine/xslt/msgs.properties" 
          prefix="" 
          pattern="(XSLTSE-[4-7]\d\d\d)(: )(.*)"/>  
    <!-- Copy the generated file to the build output directory to be packaged with jar --> 
    <copy file="${project.build.sourceDirectory}/com/sun/jbi/engine/xslt/msgs.properties" 
          todir="${project.build.outputDirectory}/com/sun/jbi/engine/xslt"/>

i18n Attributes

dir

The Ant task parses the compiled binary files searching for messages by the specified message identifier pattern, which is why the task is called after the compile phase. This attribute points to the build output directory for your component project.

file

This is the location to which the message bundle file is generated. Note the generation occurs to the build source directory, which is usually a no-no because no build step is allowed to overwrite source-managed files. The Ant task will not overwrite a file that hasn't changed since the last generation. Keep this in mind when managing your source files in version control and ALWAYS check in the newly generated bundle file.

prefix

The component prefix which begins every message, comprising the alpha portion of the message's unique id. Remember, pass an empty value if the prefix is already part of the message identifier pattern.

pattern

The message identifier pattern, which MUST match the pattern given to your component's I18n utility implementation's constructor. For more information on creating the standard I18n implementation, please read this blog entry.

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This particular version was published on 22-Jan-08 16:35 PM, -0800 by KevanSimpson