JBoss Community Archive (Read Only)

RHQ 4.10

GwtI18n

GWT Internationalization

This page provides an overview of how i18n is done in the coregui GWT webapp.

What Devs Need to Know

Our English messages are currently all stored in a single Java message bundle at:

coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties

The message bundle properties file should adhere to the following format:

  1. Each message key should consist of two camel-case words separated by an underscore, where the first word describes the view or component and the second word describes the specific message, e.g. resourceConfigHistory_modifiedHeader, button_cancel.

  2. The equals sign between the message key and the message should have a single space on either side of it to improve readability, e.g. button_cancel = Cancel

The message bundle gets compiled into Java by the gwt:i18n goal, and then, along with all the other coregui source files, into JavaScript by the gwt:compile goal.

In the generated Messages class, each message has a corresponding method for returning the version of that message for the current client-side locale. Here's an example of using the Messages class:

// There is a convenience method on CoreGUI to grab the Messages singleton instance.
private static final Messages MESSAGES = CoreGUI.getMessages();

// Lookup a message named "about_jbossByRedHat" with no parameters.
// i.e.: about_jbossByRedHat = JBoss by Red Hat
String jbossByRedHat = MESSAGES.about_jbossByRedHat();

// Lookup a message named "about_title" with a single parameter.
// i.e.: about_title = About {0}
String title = MESSAGES.about_title(productName);

The org.rhq.enterprise.gui.coregui.client.components.AboutModalWindow class is an example of a coregui class that has been internationalized.

For more info on how i18n is done in GWT, see the GWT i18n dev guide.

The Nitty Gritty

The following magic incantations in coregui/pom.xml ensure that this message bundle (along with any other additional bundles for other languages) is compiled by the gwt plugin's gwt:i18n goal into a Java class named org.rhq.enterprise.gui.coregui.client.Messages, which implements the com.google.gwt.i18n.client.Messages interface.

           <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/generated-sources/gwt</outputDirectory>
                  <resources>          
                    <resource>
                      <directory>src/main/resources</directory>
                      <filtering>true</filtering>
                    </resource>
                  </resources>              
                </configuration>            
              </execution>
             </executions>
            </plugin>
            
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>1.2</version>
                <configuration>
                    ...
                    <i18nMessagesBundle>org.rhq.enterprise.gui.coregui.client.Messages</i18nMessagesBundle>
                    ...
                </configuration>

                <executions>
                    <execution>
                        <id>gwt-goals</id>
                        <goals>
                            ...
                            <goal>i18n</goal>
                        </goals>
                    </execution>
                    ...
                </executions>
            </plugin>

The generated source file gets written to:

coregui/target/generated-sources/gwt/org/rhq/enterprise/gui/coregui/client/Messages.java

This source file then gets compiled, along with all the other coregui classes, by the gwt:compile goal.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-11 14:04:04 UTC, last content change 2010-11-01 00:50:37 UTC.