Wednesday, 28 December 2005

An effort to localize blojsom

« A contribution to JSON-RPC-Java | Main | General considerations inspired by Ruby on Rails »

A while ago I sketched a solution to localize the blojsom public interface but I haven't time to write about it until now. So, for anyone that could find it useful:
the solution is based on ResourceManager and doesn't require any modification to source code.
It uses the Velocity dispatcher and:

  • a couple of specific velocimacros that should be added in user-macros.vm in WEB-INF/classes;
  • a set of properties files with messages' translations named lMessages_<language_code>.properties and placed in WEB-INF/classes too.
    If a user wants to be newfangled, he can add personal translations in files named <user_id>_lMessages_<language_code>.properties;
  • localized Velocity templates;
  • the DateFormatPlugin to format the dates of comments and trackbacks. In fact, differently from org.blojsom.blog.BlogEntry, the classes org.blojsom.blog.BlogComment and org.blojsom.blog.Trackback don't have a method getDateAsFormat with a parameter of type java.util.Locale.

The translation's file is choosen depending on the language code specified in blog configuration.

At http://superfluo.org/blojsom-resources/ you can find:

To localize your Asual theme, simply:

  1. configure conveniently DateFormatPlugin,
  2. tar xzf blojsom-l-messages.tgz in WEB-INF/classes,
  3. if your desired language code is different from en or it, add in WEB-INF/classes a new resources file named lMessages_<language_code>.properties :-) ,
  4. substitute standard Asual templates and resources with the localized ones in blojsom-asual.tgz,
  5. set blog-language=<language_code> in WEB-INF/<user-id>/blog.properties,
  6. restart servlet container.

Why not to simply create different templates for different languages? Because, in my opinion:

  • it's easier to mantain a set of message sources than a set of templates. This is a crucial point for blojsom developers but is unhelpful for us users :-) ,
  • in this way, the blog's owner can change the language with a very simple operation that can be done also by inexperienced users. This could be important in many situations, expecially when new blogs are added frequently.

Superfluos and Sakscia are using this solution.

Known problems:
  • many (harmless) ERROR log messages are generated by the attempt by velocimacro lMsgF to read a user messages file, when this last one is missing.
Posted by Nicola Piccinini at 5:21 PM CET in blojsom/