You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by daljeetsingh <da...@softhome.net> on 2001/05/06 15:23:32 UTC

Resource Bundle in Velocity

Hello,

>>>$$bundle.getString("key") 

>>>to get a string, and put the right bundle into the context for the
>>>required locale of the client.

That does work but what actually doesn't work is:

$MessageFormat.format($bundle.getString("key"), new Object[] {"name"} ) 

This has to be done since my properties files contain something like
Welcome {0} or Willkommen {0} based on the locale. 

Will it be a good idea to add some sort of API to Velocity for doing
this?

Thanks,
Daljeet Singh 
ecExperts India 
Ph:- (O) +91-11-4670906
(R) +91-11-7125680 
ICQ:- 75129600
Yahoo:- daljeetsinghmaken 

Re[2]: Re[2]: Resource Bundle in Velocity

Posted by daljeetsingh <da...@softhome.net>.
Well I am new too. But I imagine having multiple resource bundle files
so that they can be managed properly in a bigger project environment.

So you might want to break the resource bundle files based on the
modules in your project. For example a set of resource files (for
different locales) for a module say cart management and than another set
of resources for say user management. 

Than while preparing the UI designer/programmer can decide what
resources to load and use.

Daljeet Singh 

Re: Resource Bundle in Velocity

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
daljeetsingh wrote:
> 
> All this has to kind of reinvent the wheel? What do you think of the
> idea where I can use the various tag libraries within my velocity
> templates.

I would *love* that.  I have been thinking about that for a while - I
want to make a little framework where we can just hijack any tag library
made and use them from the context as tools.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re: Re[2]: Resource Bundle in Velocity

Posted by bob mcwhirter <bo...@werken.com>.
> Implementation ideas: Lets see
> 
> I have used i18n taglibrary from TAGLIBS project and there is this
> process that has to be carried out:
> 
> 1. Load all (more than 1 can be loaded) the correct resource bundle
> files. The locale object can be in your session / request object. 

Admittedly, I'm still kinda new to i18n/l10n, but from my cursory
readings, don't you mostly end up with one bundle, chained to
others, providing 'fall-through' defaults kind of thing?

	-bob


Re[2]: Resource Bundle in Velocity

Posted by daljeetsingh <da...@softhome.net>.
Implementation ideas: Lets see

I have used i18n taglibrary from TAGLIBS project and there is this
process that has to be carried out:

1. Load all (more than 1 can be loaded) the correct resource bundle
files. The locale object can be in your session / request object. 

2. Refer to the keys wherever you want to show labels etc. Here if we
should have the possibility of sending a Object[] to the key. The tag
library does this by adding a messageArg tag within the message tag.

All this has to kind of reinvent the wheel? What do you think of the
idea where I can use the various tag libraries within my velocity
templates.

Thanks
Daljeet Singh 
ecExperts India 
Ph:- (O) +91-11-4670906
(R) +91-11-7125680 
ICQ:- 75129600
Yahoo:- daljeetsinghmaken 

Re: Resource Bundle in Velocity

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
bob mcwhirter wrote:
> 
> > > I *know* that this is something I'm going to have to deal
> > > with at work.
> >
> > Hi bob!  Good to see you again!
> 
> Oh, I've always been here.  Just quiet.  I've directed a cow-orker
> of mine to do the UI layer of our current project (we've selected,
> Velocity; no suprise there...).
> 
> > Yep - for two reasons, I think : 1) There is no reason to believe that
> > this is velocity specific code, or core velocity 2) it would be a great
> > thing to share with others.  I want to start a commons project where we
> > collect all the servlet / ui / etc utils and tools and bring them
> > together.  This would be a great addition, christoph has a few, a client
> > of mine has a result set reporting formatter ui bean thing...
> 
> Cool.  The only thing I'm questioning right now is the ability
> to deal with arrays of substitution data.  Kinda ends up being
> somewhat printf-esque.
> 
> I forgot, did Velocity ever end up with a VARARGS type of thing?

Yes - directives are vararg - you can specify an arbitrary number if you
were going to write a directive to do this.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re: Resource Bundle in Velocity

Posted by bob mcwhirter <bo...@werken.com>.
> > I *know* that this is something I'm going to have to deal
> > with at work.
> 
> Hi bob!  Good to see you again!

Oh, I've always been here.  Just quiet.  I've directed a cow-orker
of mine to do the UI layer of our current project (we've selected,
Velocity; no suprise there...).

> Yep - for two reasons, I think : 1) There is no reason to believe that
> this is velocity specific code, or core velocity 2) it would be a great
> thing to share with others.  I want to start a commons project where we
> collect all the servlet / ui / etc utils and tools and bring them
> together.  This would be a great addition, christoph has a few, a client
> of mine has a result set reporting formatter ui bean thing...

Cool.  The only thing I'm questioning right now is the ability
to deal with arrays of substitution data.  Kinda ends up being
somewhat printf-esque.  

I forgot, did Velocity ever end up with a VARARGS type of thing?

	-bob


Re: Resource Bundle in Velocity

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
bob mcwhirter wrote:
> 
> > Hello,
> >
> > >>>$$bundle.getString("key")
> >
> > >>>to get a string, and put the right bundle into the context for the
> > >>>required locale of the client.
> >
> > That does work but what actually doesn't work is:
> >
> > $MessageFormat.format($bundle.getString("key"), new Object[] {"name"} )
> >
> > This has to be done since my properties files contain something like
> > Welcome {0} or Willkommen {0} based on the locale.
> >
> > Will it be a good idea to add some sort of API to Velocity for doing
> > this?
> 
> I *know* that this is something I'm going to have to deal
> with at work.

Hi bob!  Good to see you again!
 
> I'm betting that hopefully we don't have to actually extend
> Velocity proper, and do it all with helper objects in the
> context.

Yep - for two reasons, I think : 1) There is no reason to believe that
this is velocity specific code, or core velocity 2) it would be a great
thing to share with others.  I want to start a commons project where we
collect all the servlet / ui / etc utils and tools and bring them
together.  This would be a great addition, christoph has a few, a client
of mine has a result set reporting formatter ui bean thing...
 
> If you have implementation ideas, I'd love to hear'em.  Else,
> we'll probably also develop an implementation, and at some point,
> donate it back to the project.

very cool!

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re: Resource Bundle in Velocity

Posted by bob mcwhirter <bo...@werken.com>.
> Hello,
> 
> >>>$$bundle.getString("key") 
> 
> >>>to get a string, and put the right bundle into the context for the
> >>>required locale of the client.
> 
> That does work but what actually doesn't work is:
> 
> $MessageFormat.format($bundle.getString("key"), new Object[] {"name"} ) 
> 
> This has to be done since my properties files contain something like
> Welcome {0} or Willkommen {0} based on the locale. 
> 
> Will it be a good idea to add some sort of API to Velocity for doing
> this?

I *know* that this is something I'm going to have to deal 
with at work.  

I'm betting that hopefully we don't have to actually extend
Velocity proper, and do it all with helper objects in the 
context.

If you have implementation ideas, I'd love to hear'em.  Else,
we'll probably also develop an implementation, and at some point,
donate it back to the project.

	-bob