You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Chris Bailey <ch...@adobe.com> on 2005/01/13 06:09:25 UTC

Question on using text from resource bundles

I¹m relatively new to Velocity and have one issue I¹m trying to find out
more info on.  I¹m using Velocity for a web app, and one that will be
localized in many languages.  So, for my web pages (which are all done via
Velocity), I¹d like to retrieve text via a resource bundle, and further, to
have some of the abilities provided by MessageFormat.  Essentially, I¹m
looking for something similar to the ³fmt² JSTL tags (³fmt:message² and its
subtag ³fmt:param²).

Or, a better question might be, what would the ³best practices² be for
Velocity in this regard?  How are people doing this type of thing when using
Velocity?  It seems reasonable to put this in your view/Velocity markup, as
it¹s view/presentation specific, but I haven¹t been able to find any
information on this kind of thing.

I apologize if I¹ve missed this in the docs or mailing list archives, so if
it¹s there, please redirect me.

__ 
Christopher Bailey
Adobe Systems Incorporated


Re: Question on using text from resource bundles

Posted by Shinobu Kawai Yoshida <sh...@gmail.com>.
Great work, Florin!

Maybe you can contribute it on the wiki when you're done with it.  :)
    http://wiki.apache.org/jakarta-velocity/VelocityTools

> It happens I was stumbling on the same issue at the time the thread was
> started.
> This is what I came up with for my purposes.
> Maybe it helps.
> (I would not mind one changing the package of the class if using it as-is. I
> just attached my current copy).

Best regards,
-- Shinobu

--
Shinobu "Kawai" Yoshida <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Question on using text from resource bundles

Posted by Florin Vancea <fv...@maxiq.ro>.
It happens I was stumbling on the same issue at the time the thread was
started.
This is what I came up with for my purposes.
Maybe it helps.
(I would not mind one changing the package of the class if using it as-is. I
just attached my current copy).
Florin

----- Original Message ----- 
From: "Shinobu Kawai Yoshida" <sh...@gmail.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Friday, January 14, 2005 3:01 AM
Subject: Re: Question on using text from resource bundles


> Hi Mike,
>
> > Or you could just write your own custom velocity tool (perhaps using the
> > struts one as a basis) if that's not a good fit.   A velocity tool is
just a
> > java class that's stuck into the Velocity context so you can call
methods on
> > it.
>
> ResourceBundles are one of the key features for java i18n.
>    http://java.sun.com/j2se/1.4.2/docs/guide/intl/intl.doc.html#23039
>
> I would say a ResourceBundleTool (or something like that) could come
> in handy as a generic tool.  And maybe a ViewTool which uses the
> request's Locale, too.  :)
>
> Best regards,
> -- Shinobu
>
> --
> Shinobu "Kawai" Yoshida <sh...@gmail.com>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

Re: Question on using text from resource bundles

Posted by Chris Bailey <ch...@adobe.com>.
It appears that for folks using Spring MVC, that there is a springMessage
Velocity macro to assist with this.  About the only place I've found
reference to this is in the actual "spring.vm" source file, and then one
post on the Spring mailing list with the macro suggestion.  So, at least if
you're using Spring, check that out.


On 1/13/05 5:01 PM, "Shinobu Kawai Yoshida" <sh...@gmail.com> wrote:

> Hi Mike,
> 
>> Or you could just write your own custom velocity tool (perhaps using the
>> struts one as a basis) if that's not a good fit.   A velocity tool is just a
>> java class that's stuck into the Velocity context so you can call methods on
>> it.
> 
> ResourceBundles are one of the key features for java i18n.
>    http://java.sun.com/j2se/1.4.2/docs/guide/intl/intl.doc.html#23039
> 
> I would say a ResourceBundleTool (or something like that) could come
> in handy as a generic tool.  And maybe a ViewTool which uses the
> request's Locale, too.  :)
> 
> Best regards,
> -- Shinobu
> 
> --
> Shinobu "Kawai" Yoshida <sh...@gmail.com>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 

__ 
Christopher Bailey
Senior Computer Scientist
Online Services Engineering
Adobe Systems Incorporated
mailto: chbailey@adobe.com
Rocklin Vox: 916.415.0471



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Question on using text from resource bundles

Posted by Shinobu Kawai Yoshida <sh...@gmail.com>.
Hi Mike,

> Or you could just write your own custom velocity tool (perhaps using the
> struts one as a basis) if that's not a good fit.   A velocity tool is just a
> java class that's stuck into the Velocity context so you can call methods on
> it.

ResourceBundles are one of the key features for java i18n.
   http://java.sun.com/j2se/1.4.2/docs/guide/intl/intl.doc.html#23039

I would say a ResourceBundleTool (or something like that) could come
in handy as a generic tool.  And maybe a ViewTool which uses the
request's Locale, too.  :)

Best regards,
-- Shinobu

--
Shinobu "Kawai" Yoshida <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Question on using text from resource bundles

Posted by Mike Kienenberger <mk...@alaska.net>.
Chris Bailey <ch...@adobe.com> wrote:
> I�m relatively new to Velocity and have one issue I�m trying to find out
> more info on.  I�m using Velocity for a web app, and one that will be
> localized in many languages.  So, for my web pages (which are all done via
> Velocity), I�d like to retrieve text via a resource bundle, and further, 
to
> have some of the abilities provided by MessageFormat.  Essentially, I�m
> looking for something similar to the �fmt� JSTL tags (�fmt:message� and 
its
> subtag �fmt:param�).
> 
> Or, a better question might be, what would the �best practices� be for
> Velocity in this regard?  How are people doing this type of thing when 
using
> Velocity?  It seems reasonable to put this in your view/Velocity markup, 
as
> it�s view/presentation specific, but I haven�t been able to find any
> information on this kind of thing.

I use Struts and velocity.   Struts contains a MessageResource class to 
handle this, and Velocity makes it available via the Struts tools.

I believe that the MessageResource classes have now been made into a 
separate Apache Commons MessageResources class, and that might be something 
for you to look into.

Or you could just write your own custom velocity tool (perhaps using the 
struts one as a basis) if that's not a good fit.   A velocity tool is just a 
java class that's stuck into the Velocity context so you can call methods on 
it.

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org