velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Revusky <jrevu...@terra.es>
Subject Re: template encodings
Date Sun, 15 Jul 2001 13:49:38 GMT
"Geir Magnusson Jr." wrote:
> 
> Jonathan Revusky wrote:
> >
> > I have the Velocity developer guide doc in front of me and I'm looking
> > at the section entitled "Template Encoding for Internationalization".
> >
> > There is a method called mergeTemplate that takes the encoding as an
> > argument.
> >
> > My belief is that once you figure out the desired locale, and call
> > response.setLocale(myLocale) that simply by writing to the Writer object
> > returned by response.getWriter() that it will (should) be encoded
> > appropriately.
> 
> I am not sure what you are getting at - but note that the encoding
> argument to mergeTemplate() is the encoding of the *template*, not the
> output.  The encoding of the output stream is something else entirely.

Are you sure you meant to say the above? That mergeTemplate AFAICS is
clearly used to output. You already have a read pre-parsed template
object at that stage. 

But I think I understand the issue now anyhow.

It seems to me that this kind of helper method is necessary, since you
aren't always using velocity from within a servlet engine. That had
slipped my mind.

> 
> mergetTemplate() is a utility method provided by the Velocity helper
> class to allow you to easily render a template.  The usual mechanism is
> to use the pattern of
> 
> Template t = getTemplate( name, encoding );

This one, I was not using in my code. Now I have patched it though. I
assume that a template found via the name_zh_TW.html lookup scheme is
encoded in the encoding for that locale (Taiwan) which is "Big5". Though
I don't know how safe an assumption that is.

I don't know whether anybody is using all this structure, since if you
don't specify a locale, then it's default locale and default encoding
all ways around, which surely tends to work for unilingual web sites.
I've tried to go the extra mile in my framework to do the right things
transparently, but I don't have feedback from people as to whether it
works for Asian languages etcetera.

> t.merge( context, writer);

This is the method I was using it turns out.

> 
> so you see, fundamentally the two steps are distinct.  You could merge
> the same template repeatedly with different writers that use different
> encodings, if you wished.

Yes, that's true, though I don't know if it's really a likely scenario.

Thanks. When I wrote the note, actually it did slip my mind that
Velocity might be used in non-servlet contexts, so that does explain the
separate mergeTemplate helper code.


Jonathan Revusky
--
available for Java/Delphi/Internet consulting
If you want to...
- make your .class files double-clickable with SmartJ
- do Delphi/Java mixed programming with easy-to-use JNI wrapper classes
- build robust web applications with the Niggle Application Framework
then...
check out the Revusky Hacks Page: http://www.revusky.com/hacks/

Mime
View raw message