You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Graham <dg...@hotmail.com> on 2002/08/08 21:21:47 UTC

I18N and locales

When using the <bean:message> tag do you have to supply a different locale 
key to change the language it uses?  I was under the impression that struts 
handles this automatically but reading the docs again seemed to indicate 
otherwise.  I use the tag like this:
<bean:message key="button.add"/>

If a browser hits the page and specifies a different locale than english, 
does struts select the right resource file or do I have to do something?

Also, in one of my actions, after I save info to a database, I want to put a 
message in the request before I forward to the success page.  The success 
page would display whatever message it receives.  What struts class do I use 
in java code to retrieve i18n messages like the bean:message tag?

Thanks,
Dave



_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


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


Re: I18N and locales

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 8 Aug 2002, David Graham wrote:

> Date: Thu, 08 Aug 2002 13:21:47 -0600
> From: David Graham <dg...@hotmail.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: struts-user@jakarta.apache.org
> Subject: I18N and locales
>
> When using the <bean:message> tag do you have to supply a different locale
> key to change the language it uses?  I was under the impression that struts
> handles this automatically but reading the docs again seemed to indicate
> otherwise.  I use the tag like this:
> <bean:message key="button.add"/>
>
> If a browser hits the page and specifies a different locale than english,
> does struts select the right resource file or do I have to do something?
>

Struts manages the choice of language by maintaining a Locale object under
a well-known session attribute key (Action.LOCALE_KEY).  If there isn't
one already, it is set automatically based on the browser's
Accept-Language header.  However, your app can replace the default one --
for example, if you offered a "select language" option.

> Also, in one of my actions, after I save info to a database, I want to put a
> message in the request before I forward to the success page.  The success
> page would display whatever message it receives.  What struts class do I use
> in java code to retrieve i18n messages like the bean:message tag?
>

If you have internationalized the text of the message already, you can
just store the String as a request or session attribute, and display it
with the <bean:write> tag.  For example (assuming you stored the text
as a request attribute named "foo"):

  <bean:write name="foo"/>

If you want the output page to internationalize the text (by looking it up
in your application resources), store the message *key* as a request or
session attribute, and use that as the argument to a <bean:message> call
on the destination page.  For example (assuming you stored the correct key
as a request attribute named "foo"):

  <bean:message key='<%= (String) request.getAttribute("foo") %>'/>


> Thanks,
> Dave
>

Craig


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