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
inWEB-INF/classes
; - a set of properties files with messages' translations named
lMessages_<language_code>.properties
and placed inWEB-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 classesorg.blojsom.blog.BlogComment
andorg.blojsom.blog.Trackback
don't have a methodgetDateAsFormat
with a parameter of typejava.util.Locale
.
The translation's file is choosen depending on the language code specified in blog configuration.
At https://superfluo.org/blojsom-resources/ you can find:
- blojsom-l-messages.tgz, contains the velocimacros and properties files with standard (English) strings and (my opinable) Italian translations,
- blojsom-asual.tgz, contains localized Asual theme,
- blojsom-grid.tgz, contains localized Grid theme.
To localize your Asual theme, simply:
- configure conveniently DateFormatPlugin,
tar xzf blojsom-l-messages.tgz in WEB-INF/classes
,- if your desired language code is different from en
or it, add in
WEB-INF/classes
a new resources file namedlMessages_<language_code>.properties
:-) , - substitute standard Asual templates and resources with the localized ones in
blojsom-asual.tgz
, - set
blog-language=<language_code>
inWEB-INF/<user-id>/blog.properties
, - 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 blojsom/
at 5:21 PM CET in