You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Struts Newsgroup (@Basebeans.com)" <st...@basebeans.com> on 2002/07/11 16:10:02 UTC

How to automaticlly set the locale according to user's request

Subject: How to automaticlly set the locale according to user's request
From: "Alex Kwan" <er...@hotmail.com>
 ===
Hi, All
    I want to build a multilanguage site with structs. As we all know, the
response encode the content to client using the charaterset defined by
setLocale() or setContentType().If the we don't set the locale, it will use
the default "ISO-8859-1".
Now the question is:
1.I want to setLocale() by the value get from request.getLocale(), but how
can I set the struts to automaticlly finish this process.
2.How can I set the web to make jsp also automaticlly encoding the content
using the client locale setting.

Thanks.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to automaticlly set the locale according to user's request

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Struts Newsgroup (@Basebeans.com) <st...@basebeans.com>:

> Now the question is:
> 1.I want to setLocale() by the value get from request.getLocale(),
> but how can I set the struts to automaticlly finish this process.

This happens automatically, I think, if you don't override it by
setting the Action.LOCALE_KEY attribute on the session.

> 2.How can I set the web to make jsp also automaticlly encoding the
> content using the client locale setting.

If you mean, "how can I change the output language based on the
browsers' locale settings?", then the answer in Struts 1.0, is that
you can use the <bean:message> tag to look up a language dependent
text from a resource bundle.

Eg. if you have the file MyResources.properties containing
	helloworld=Hello World!
and the file MyResources_no.properties containing
	helloworld=Hei Verden!
both at the top level of the WEB-INF directory, and put
  <servlet>
    ...
    <init-param>
      <param-name>application</param-name>
      <param-value>MyResources</param-value>
    </init-param>
    ...
  </servlet>
in the web.xml file, then using
  <bean:message key="helloworld"/>
will render the text "Hei Verden!" if the browser's locale is "no",
and "Hello World!" for all others.

See
	<http://www.anassina.com/struts/i18n/i18n.html>
for some tips.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>