[Webwork-devel] Adding i18n and text support to Velocity
Brought to you by:
baldree,
rickardoberg
From: Bill B. <bi...@pr...> - 2002-02-20 09:41:49
|
Hello, I've been looking into the best way to add support for the equivalent of the ww:i18n and ww:text JSP tags to Velocity. One thing that seems apparent is that the ValueStack needs to be exposed to Velocity templates in some manner. This is at least true to get the i18n functionality to work and may be necessary in other cases as well. I'm planning on adding the ValueStack to the VelocityContext so it can be accessed via the key $valuestack. However, most usage will be wrapped in macros like #pushvalue() and #popvalue() so users won't access $valuestack directly. For user visible methods such as findValue() and test(), I've modified WebWorkUtil adding these methods to the delegate to the same ValueStack methods. This will allow these methods can be called using the syntax $webwork.methodName(). In the case of findValue() that will probably be available as $webwork.value(...). In the case of i18n support there would be an i18n macro that would be called like this: #i18n("webwork.action.test.i18n.Shop") By definition it would push the specified ResourceBundle on the ValueStack thereby allowing the text support to use that ResourceBundle instead of the default. However, because this macro isn't a block tag, there needs to be some way of popping the ResourceBundle off the ValueStack. To do this, I was going to expose the ValueStack popValue() method within a macro: #popvalue() Which would be implemented as $valuestack.popValue(). In like manner there are times when an Action or Bean needs to be pushed onto the stack. For instance: #action("i18n.Shop", $shop) #pushvalue($shop) ... #execute($shop) ... #popvalue() I'm also looking into making an i18n block directive which would scope the ResourceBundle instance as in: #i18n("webwork.action.test.i18n.Shop") ... #end If I can get that to work, the popValue will be implied at the #end. As far as support for text goes, I'm planning on adding a several text() methods to WebWorkUtil. As a result, they'll be available via the $webwork context name. $webwork.text(key) $webwork.text(key, param0) etc. In order to implement the parameter support, I'll copy the TextTag class into the .velocity package and rework it with more appropriate API's for Velocity. After the 1.0 release, these two classes could be refactored so they call a common class in .util. Thanks for any feedback, -Bill |