Friday, April 8, 2011

GWT Server-side Internationalization With Hermes

Greetings interwebs! My name is Matt Bertolini and I am an engineer here at Travel Tripper. I thought it was about time I made an appearance on our tech blog. I want to talk about a new project called Hermes that I have recently finished and am sharing with the world.



A Little Backstory



Our application, RezTrip, is in the process of being internationalized. Since it is a GWT based application, we chose to use the GWT static string internationalization features. Unfortunately, these features only work on the GWT client-side and we have lots of other client-facing strings that need to be internationalized (client emails, legacy HTML pages, etc.).

The gwt-i18n-server Library

A quick Google search on the subject of "server-side GWT i18n" found a library called gwt-i18n-server. This library gives the server-side support for the GWT static string i18n interfaces and properties files. We quickly incorporated the library into RezTrip and found it was pretty buggy. Worse yet, development on the library had stagnated and hadn't been updated in over a year. This is where I come in. Not satisfied with admitting defeat and implementing a separate i18n system just for server-side content, I decided to fork the gwt-i18n-server library and fix the bugs.

Enter Hermes

Hermes is the name of my fork of the gwt-i18n-server library. It is named after the Greek god Hermes (the god of language, and the great messenger of the gods). While technically a fork, every line of code has been re-written to improve compatibility with GWT and fix bugs. Here are the list of features and supported technologies found in the library:
  • GWT Constants, ConstantsWithLookup, and Messages interface support

  • Plural forms support
  • Date and number sub-formatting

  • UTF-8 properties file support
Using Hermes is very simple. All you need to do is pass the your GWT i18n class and the desired language tag to Hermes and it will create the necessary proxy class and load the appropriate properties file. Then all you need to do is call the methods on your class just like you do on the GWT client-side. Here is a small example to get you started:
ExampleMessages messages = Hermes.get(ExampleMessages.class, "en-us");
messages.sampleString();
Hermes also has a complete suite of unit tests to make sure the library is functioning as intended. The best part of Hermes it is completely free and open source, licensed under the same LGPL license as the gwt-i18n-server library. I encourage anyone using GWT to check out the library. To grab a copy or download/view the source, visit the Hermes page on GitHub. If you do use Hermes, feel free to let us know how it goes.

3 comments:

  1. Thanks for this post. I'm trying to use hermes in my application. It works in dev mode but not when deployed to the server.

    In dev mode I get this message:
    "[WARN] Server class 'com.ibm.icu.util.ULocale' could not be found in the web app, but was found on the system classpath"

    and then it loads ULocale from gwt-dev.jar.

    In production, however, it won't work because gwt-dev.jar is not being deployed.

    gwt-dev.jar is not supposed to be deployed as all what server side needs is in gwt-server.jar.

    So, how do you get this working in your application?

    Peter

    ReplyDelete
  2. Hi,
    Your code isn't thread safe. I think You should mention it somewhere in docs...especially since it's meant to be used in server(e.g. cache and createProxy in Hermes.java)

    Anyway thanks for the project. We are using it too. :)

    ReplyDelete