You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Rolf Schmidiger <gi...@active.ch> on 2003/12/04 22:45:36 UTC

Internationalization, Servlet, Accept-Language

Hy there

I'm currently writing a web-app using velocity. Now i want to
internationalize my velocity application. And here's my question:

How can i easily implement such a functionality?: i want to use the 
HTTP "Accept-Language" Header to decide which language the app should
return.

The template files should be handled like the apache mod_negotiation module
(http://httpd.apache.org/docs/mod/mod_negotiation.html):

myTemplate.vm (is the "else" case)
myTemplate.vm.de (for swiss ; ->)
myTemplate.vm.it (for italians)

O.k. Trying to call "getTemplate()" and catching  the Exception is an
option, but simply not a good idea. I am currently having several "ideas":
- implementing a org.apache.velocity.runtime.resource.loader.ResourceLoader
?
(how do i pass the Accept-Language? (String[]!)
- simply checking if the file exists by checking the filesystem
(i loose the flexibility changing the ResourceLoader in the future)

The "problem" would also be solved if there would be a
"RuntimeSingleton.doesExistsTemplate()" method ;-y

Thanks for some ideas! (and solutions of course)

Cheers

rolf


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


Re: Internationalization, Servlet, Accept-Language

Posted by Will Glass-Husain <wg...@forio.com>.
Nice!   Don't know how I missed it.  Maybe because I was searching for it in
the Resource Loader API.  Anyway, that's helpful for me as well.

WILL

> and further, adding the method
> templateExists(String name)
> Does that solve your problem?

----- Original Message ----- 
From: "Geir Magnusson Jr" <ge...@4quarters.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Tuesday, December 09, 2003 1:00 AM
Subject: Re: Internationalization, Servlet, Accept-Language


>
> On Dec 4, 2003, at 4:45 PM, Rolf Schmidiger wrote:
>
> > Hy there
> >
> > I'm currently writing a web-app using velocity. Now i want to
> > internationalize my velocity application. And here's my question:
> >
> > How can i easily implement such a functionality?: i want to use the
> > HTTP "Accept-Language" Header to decide which language the app should
> > return.
> >
> > The template files should be handled like the apache mod_negotiation
> > module
> > (http://httpd.apache.org/docs/mod/mod_negotiation.html):
> >
> > myTemplate.vm (is the "else" case)
> > myTemplate.vm.de (for swiss ; ->)
> > myTemplate.vm.it (for italians)
> >
> > O.k. Trying to call "getTemplate()" and catching  the Exception is an
> > option, but simply not a good idea. I am currently having several
> > "ideas":
> > - implementing a
> > org.apache.velocity.runtime.resource.loader.ResourceLoader
> > ?
> > (how do i pass the Accept-Language? (String[]!)
> > - simply checking if the file exists by checking the filesystem
> > (i loose the flexibility changing the ResourceLoader in the future)
> >
> > The "problem" would also be solved if there would be a
> > "RuntimeSingleton.doesExistsTemplate()" method ;-y
>
> Oh, geeze.  Don't ever use RuntimeSingleton. :)  Seriously, you don't
> want to depend on RuntimeSingleton.  We'll add something to the javadoc
> to that effect.
>
> That's why we went through the trouble of adding
>
> o.a.v.app.Velocity  and o.a.v.app.VelocityEngine
>
> and further, adding the method
>
> templateExists(String name)
>
> Does that solve your problem?
>
> geir
>
> -- 
> Geir Magnusson Jr                                   203-247-1713(m)
> geir@4quarters.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>


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


Re: Internationalization, Servlet, Accept-Language

Posted by Nathan Bubna <na...@esha.com>.
Geir Magnusson said:
> On Dec 9, 2003, at 1:26 PM, mr.x wrote:
...
> > Anyway, currently i use the RuntimeSingleton indirectly (with the
> > VelocityServlet).
>
> Hm.  Well, then you have a problem :)  Do the servlets in Vel tools use
> Velocity or VelocityEnvgine?
...

the VelocityViewServlet currently uses Velocity (just like the VelocityServlet
it used to extend).  plans are to switch to VelocityEngine after 1.1 final is
released.

Nathan Bubna
nathan@esha.com


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


RE: Internationalization, Servlet, Accept-Language

Posted by "mr.x" <mr...@tele2.ch>.
Hi Geir

The VelocityViewServlet.java (1.0) uses the RuntimeSingleton for sure. I've
changed my code and i'm now using the VelocityEngine. It works much better
now !

Thanks for the advice!

Rolf

-----Original Message-----
From: Geir Magnusson [mailto:geirm@adeptra.com] 
Sent: Mittwoch, 10. Dezember 2003 08:57
To: Velocity Users List
Subject: Re: Internationalization, Servlet, Accept-Language



On Dec 9, 2003, at 1:26 PM, mr.x wrote:

> Hi Geir
>
> Thanx for your answer. A boolean templateExists("myTemplate") method 
> would solve my problem (and problems of others replying to the 
> thread).

It exists in the Velocity and VelocityEngine classes

>
> The RuntimeSingleton.doesExistsTemplate() method was just a sample to
> describe my ideas ;->
>
> Anyway, currently i use the RuntimeSingleton indirectly (with the
> VelocityServlet).

Hm.  Well, then you have a problem :)  Do the servlets in Vel tools use 
Velocity or VelocityEnvgine?

geir

>
> Regards
> Rolf
>
>
>
> -----Original Message-----
> From: Geir Magnusson Jr [mailto:geir@4quarters.com]
> Sent: Dienstag, 9. Dezember 2003 10:01
> To: Velocity Users List
> Subject: Re: Internationalization, Servlet, Accept-Language
>
>
>
> On Dec 4, 2003, at 4:45 PM, Rolf Schmidiger wrote:
>
>> Hy there
>>
>> I'm currently writing a web-app using velocity. Now i want to
>> internationalize my velocity application. And here's my question:
>>
>> How can i easily implement such a functionality?: i want to use the
>> HTTP "Accept-Language" Header to decide which language the app should 
>> return.
>>
>> The template files should be handled like the apache mod_negotiation
>> module
>> (http://httpd.apache.org/docs/mod/mod_negotiation.html):
>>
>> myTemplate.vm (is the "else" case)
>> myTemplate.vm.de (for swiss ; ->)
>> myTemplate.vm.it (for italians)
>>
>> O.k. Trying to call "getTemplate()" and catching  the Exception is an
>> option, but simply not a good idea. I am currently having several
>> "ideas":
>> - implementing a 
>> org.apache.velocity.runtime.resource.loader.ResourceLoader
>> ?
>> (how do i pass the Accept-Language? (String[]!)
>> - simply checking if the file exists by checking the filesystem (i 
>> loose the flexibility changing the ResourceLoader in the future)
>>
>> The "problem" would also be solved if there would be a
>> "RuntimeSingleton.doesExistsTemplate()" method ;-y
>
> Oh, geeze.  Don't ever use RuntimeSingleton. :)  Seriously, you don't
> want to depend on RuntimeSingleton.  We'll add something to the 
> javadoc to that effect.
>
> That's why we went through the trouble of adding
>
> o.a.v.app.Velocity  and o.a.v.app.VelocityEngine
>
> and further, adding the method
>
> templateExists(String name)
>
> Does that solve your problem?
>
> geir
>
> -- 
> Geir Magnusson Jr                                   203-247-1713(m)
> geir@4quarters.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com 
                                  


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



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


Re: Internationalization, Servlet, Accept-Language

Posted by Geir Magnusson <ge...@adeptra.com>.
On Dec 9, 2003, at 1:26 PM, mr.x wrote:

> Hi Geir
>
> Thanx for your answer. A boolean templateExists("myTemplate") method 
> would
> solve my problem (and problems of others replying to the thread).

It exists in the Velocity and VelocityEngine classes

>
> The RuntimeSingleton.doesExistsTemplate() method was just a sample to
> describe my ideas ;->
>
> Anyway, currently i use the RuntimeSingleton indirectly (with the
> VelocityServlet).

Hm.  Well, then you have a problem :)  Do the servlets in Vel tools use 
Velocity or VelocityEnvgine?

geir

>
> Regards
> Rolf
>
>
>
> -----Original Message-----
> From: Geir Magnusson Jr [mailto:geir@4quarters.com]
> Sent: Dienstag, 9. Dezember 2003 10:01
> To: Velocity Users List
> Subject: Re: Internationalization, Servlet, Accept-Language
>
>
>
> On Dec 4, 2003, at 4:45 PM, Rolf Schmidiger wrote:
>
>> Hy there
>>
>> I'm currently writing a web-app using velocity. Now i want to
>> internationalize my velocity application. And here's my question:
>>
>> How can i easily implement such a functionality?: i want to use the
>> HTTP "Accept-Language" Header to decide which language the app should
>> return.
>>
>> The template files should be handled like the apache mod_negotiation
>> module
>> (http://httpd.apache.org/docs/mod/mod_negotiation.html):
>>
>> myTemplate.vm (is the "else" case)
>> myTemplate.vm.de (for swiss ; ->)
>> myTemplate.vm.it (for italians)
>>
>> O.k. Trying to call "getTemplate()" and catching  the Exception is an
>> option, but simply not a good idea. I am currently having several
>> "ideas":
>> - implementing a
>> org.apache.velocity.runtime.resource.loader.ResourceLoader
>> ?
>> (how do i pass the Accept-Language? (String[]!)
>> - simply checking if the file exists by checking the filesystem
>> (i loose the flexibility changing the ResourceLoader in the future)
>>
>> The "problem" would also be solved if there would be a
>> "RuntimeSingleton.doesExistsTemplate()" method ;-y
>
> Oh, geeze.  Don't ever use RuntimeSingleton. :)  Seriously, you don't
> want to depend on RuntimeSingleton.  We'll add something to the javadoc
> to that effect.
>
> That's why we went through the trouble of adding
>
> o.a.v.app.Velocity  and o.a.v.app.VelocityEngine
>
> and further, adding the method
>
> templateExists(String name)
>
> Does that solve your problem?
>
> geir
>
> -- 
> Geir Magnusson Jr                                   203-247-1713(m)
> geir@4quarters.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com 
                                  


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


RE: Internationalization, Servlet, Accept-Language

Posted by "mr.x" <mr...@tele2.ch>.
Hi Geir

Thanx for your answer. A boolean templateExists("myTemplate") method would
solve my problem (and problems of others replying to the thread).

The RuntimeSingleton.doesExistsTemplate() method was just a sample to
describe my ideas ;->

Anyway, currently i use the RuntimeSingleton indirectly (with the
VelocityServlet).

Regards
Rolf



-----Original Message-----
From: Geir Magnusson Jr [mailto:geir@4quarters.com] 
Sent: Dienstag, 9. Dezember 2003 10:01
To: Velocity Users List
Subject: Re: Internationalization, Servlet, Accept-Language



On Dec 4, 2003, at 4:45 PM, Rolf Schmidiger wrote:

> Hy there
>
> I'm currently writing a web-app using velocity. Now i want to 
> internationalize my velocity application. And here's my question:
>
> How can i easily implement such a functionality?: i want to use the 
> HTTP "Accept-Language" Header to decide which language the app should 
> return.
>
> The template files should be handled like the apache mod_negotiation
> module
> (http://httpd.apache.org/docs/mod/mod_negotiation.html):
>
> myTemplate.vm (is the "else" case)
> myTemplate.vm.de (for swiss ; ->)
> myTemplate.vm.it (for italians)
>
> O.k. Trying to call "getTemplate()" and catching  the Exception is an 
> option, but simply not a good idea. I am currently having several
> "ideas":
> - implementing a
> org.apache.velocity.runtime.resource.loader.ResourceLoader
> ?
> (how do i pass the Accept-Language? (String[]!)
> - simply checking if the file exists by checking the filesystem
> (i loose the flexibility changing the ResourceLoader in the future)
>
> The "problem" would also be solved if there would be a 
> "RuntimeSingleton.doesExistsTemplate()" method ;-y

Oh, geeze.  Don't ever use RuntimeSingleton. :)  Seriously, you don't 
want to depend on RuntimeSingleton.  We'll add something to the javadoc 
to that effect.

That's why we went through the trouble of adding

o.a.v.app.Velocity  and o.a.v.app.VelocityEngine

and further, adding the method

templateExists(String name)

Does that solve your problem?

geir

-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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



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


Re: Internationalization, Servlet, Accept-Language

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Dec 4, 2003, at 4:45 PM, Rolf Schmidiger wrote:

> Hy there
>
> I'm currently writing a web-app using velocity. Now i want to
> internationalize my velocity application. And here's my question:
>
> How can i easily implement such a functionality?: i want to use the
> HTTP "Accept-Language" Header to decide which language the app should
> return.
>
> The template files should be handled like the apache mod_negotiation 
> module
> (http://httpd.apache.org/docs/mod/mod_negotiation.html):
>
> myTemplate.vm (is the "else" case)
> myTemplate.vm.de (for swiss ; ->)
> myTemplate.vm.it (for italians)
>
> O.k. Trying to call "getTemplate()" and catching  the Exception is an
> option, but simply not a good idea. I am currently having several 
> "ideas":
> - implementing a 
> org.apache.velocity.runtime.resource.loader.ResourceLoader
> ?
> (how do i pass the Accept-Language? (String[]!)
> - simply checking if the file exists by checking the filesystem
> (i loose the flexibility changing the ResourceLoader in the future)
>
> The "problem" would also be solved if there would be a
> "RuntimeSingleton.doesExistsTemplate()" method ;-y

Oh, geeze.  Don't ever use RuntimeSingleton. :)  Seriously, you don't 
want to depend on RuntimeSingleton.  We'll add something to the javadoc 
to that effect.

That's why we went through the trouble of adding

o.a.v.app.Velocity  and o.a.v.app.VelocityEngine

and further, adding the method

templateExists(String name)

Does that solve your problem?

geir

-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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


Re: Internationalization, Servlet, Accept-Language

Posted by Will Glass-Husain <wg...@forio.com>.
> Still, I agree... it might be nice for Velocity to answer the question,
> "Do you have a template with this name?" Add the feature request in
> BugZilla, I guess.


seconded.  (maybe thirded?).  Please do put this in BugZilla.

I've got an app that looks for one template, then if it's not available,
looks for another.  The exception catching system works, but I get a lot of
ERROR messages in the log.  Be better if I could just check availability.

Best,
WILL

----- Original Message ----- 
From: "J. B. Rainsberger" <jb...@rogers.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Friday, December 05, 2003 11:18 AM
Subject: Re: Internationalization, Servlet, Accept-Language


> Claude Brisson wrote:
>
> >>O.k. Trying to call "getTemplate()" and catching  the Exception is an
> >>option, but simply not a good idea.
> >
> >
> > Ah ? Why ? It is the shortest and simplest option... Exceptions CAN be
used in a normal processing :-)
>
> I agree, but for a different reason.
>
> I, too, dislike using exceptions for cases that I do not think are
> exceptional. Unfortunately, when using an outside API, you /should/ use
> the API the way it is meant to be used. Unfortunately, Velocity expects
> you to simply ask for the template and it complains (through an
> Exception) when it cannot find the template. Until Velocity adds the
> ability to ask whether a template exists, I recommend using the API as
> is, rather than inventing your own way around the problem.
>
> Still, I agree... it might be nice for Velocity to answer the question,
> "Do you have a template with this name?" Add the feature request in
> BugZilla, I guess.
> -- 
> J. B. Rainsberger,
> Diaspar Software Services
> http://www.diasparsoftware.com :: +1 416 791-8603
> Let's write software that people understand
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>


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


Re: Internationalization, Servlet, Accept-Language

Posted by "J. B. Rainsberger" <jb...@rogers.com>.
Claude Brisson wrote:

>>O.k. Trying to call "getTemplate()" and catching  the Exception is an
>>option, but simply not a good idea.
> 
> 
> Ah ? Why ? It is the shortest and simplest option... Exceptions CAN be used in a normal processing :-)

I agree, but for a different reason.

I, too, dislike using exceptions for cases that I do not think are 
exceptional. Unfortunately, when using an outside API, you /should/ use 
the API the way it is meant to be used. Unfortunately, Velocity expects 
you to simply ask for the template and it complains (through an 
Exception) when it cannot find the template. Until Velocity adds the 
ability to ask whether a template exists, I recommend using the API as 
is, rather than inventing your own way around the problem.

Still, I agree... it might be nice for Velocity to answer the question, 
"Do you have a template with this name?" Add the feature request in 
BugZilla, I guess.
-- 
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand


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


Re: Internationalization, Servlet, Accept-Language

Posted by Claude Brisson <cl...@savoirweb.com>.
> O.k. Trying to call "getTemplate()" and catching  the Exception is an
> option, but simply not a good idea.

Ah ? Why ? It is the shortest and simplest option... Exceptions CAN be used in a normal processing :-)

CloD



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