You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Elad Messing <El...@sphera.com> on 2004/01/20 12:13:36 UTC

The recommended way to define a dynamic Charset

Hi
	I am a tapestry newbie. In my application, the user (upon
logging in) chooses its desired language. The choice is stored in the
session data, and I need to use it when rendering HTML pages for
choosing the proper Charset. So the charset is static all over the
application - but changes for each session.

	what will be your recommended way of coding this behavior ?

	Thank you

Elad Messing

Sphera Tech. LTD
 <<Picture (Metafile)>> 
<http://www.sphera.com/demosite/index.htm>



Re: The recommended way to define a dynamic Charset

Posted by Mindbridge <mi...@yahoo.com>.
The recommended way to define a dynamic CharsetHi, 

Just to add to and summarise the other responses:

The default character encoding that Tapestry uses to generate the web pages (a.k.a the output encoding) is UTF-8. 
UTF-8 is a form of Unicode and allows the browser to display pretty much all international characters at the same time (Latin, Cyrillic, Greek, Hebrew, etc).

As such, there is normally no need to change the output character set in order to display different languages. You can do that, but it is typically counter-productive.

What you could do instead is change the current active locale, which would cause Tapestry to load templates and strings for that locale. To change the locale, please do getEngine().setLocale(locale). For your purposes, after a user logs in, you can get the locale associated with that user and perform the above.

Note that by default Tapestry activates the locale that is provided by the user's browser, so in general it guesses quite well the necessary language.

>From then on you are in the fields of i18n and l10n. In Tapestry each page/component can have multiple templates and property files associated with it. For example, the Home page could have Home.html and Home_zh.html (for Chinese), as well as Home.properties and Home_zh.properties. The appropriate templates and property files will be loaded depending on the locale stored in the Engine. The strings in the property files can be accessed either by calling getMessage("key") on the page/component or by using <tag ... parameter="message:key" ... /> in the template (e.g <span jwcid="@Insert" value="message:sample_message"/>).

Finally, you can specify the encoding (character set) you've used to create your templates. See the doc on  org.apache.tapestry.template-encoding here http://jakarta.apache.org/tapestry/doc/TapestryUsersGuide/configuration.character-sets.html. This allows you to specify, for example, that your Latin templates are written in ISO-8859-1 and your Chinese templates use Big5 (even though they are in the same application). This does not affect in any way the generated HTML sent to the browser, as it will still be in UTF-8  to allow you to mix languages in any way you want.

Note that unlike templates all .property files still need to pass through the native2ascii program as it is custom for Java.
 
I hope this description answers your questions. Please do ask if something is unclear.

-mb

Re: The recommended way to define a dynamic Charset

Posted by James Treleaven <ja...@enoreo.on.ca>.
The User docs are incomplete but still quite useful.

See the discussions of the 'Visit Object'[section 3] and 'Character 
Sets'[section 4] here:
http://jakarta.apache.org/tapestry/doc/TapestryUsersGuide/TapestryUsersGuide.html

James

Elad Messing wrote:
> Hi
> 
>         I am a tapestry newbie. In my application, the user (upon 
> logging in) chooses its desired language. The choice is stored in the 
> session data, and I need to use it when rendering HTML pages for 
> choosing the proper Charset. So the charset is static all over the 
> application - but changes for each session.
> 
>         what will be your recommended way of coding this behavior ?
> 
>         Thank you
> 
> Elad Messing
> 
> Sphera Tech. LTD


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


Re: The recommended way to define a dynamic Charset

Posted by Programozás <pr...@hotmail.com>.
The recommended way to define a dynamic CharsetI think that the simplest and
less painful solution is to store all template files UTF-8 encoded.
And you should set the output-encoding to UTF-8, too.

----- Original Message ----- 
From: Elad Messing
To: tapestry-user@jakarta.apache.org
Sent: Tuesday, January 20, 2004 12:13 PM
Subject: The recommended way to define a dynamic Charset


Hi
        I am a tapestry newbie. In my application, the user (upon logging
in) chooses its desired language. The choice is stored in the session data,
and I need to use it when rendering HTML pages for choosing the proper
Charset. So the charset is static all over the application - but changes for
each session.
        what will be your recommended way of coding this behavior ?
        Thank you
Elad Messing
Sphera Tech. LTD

<http://www.sphera.com/demosite/index.htm>

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