struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: I18N and locales
Date Thu, 08 Aug 2002 19:57:49 GMT


On Thu, 8 Aug 2002, David Graham wrote:

> Date: Thu, 08 Aug 2002 13:41:48 -0600
> From: David Graham <dgraham1980@hotmail.com>
> Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> To: struts-user@jakarta.apache.org
> Subject: Re: I18N and locales
>
> Thanks for the info Craig!  More questions below...
>
> >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"/>
>
> Cool, but how do I i18n the text so that I can put it in the request?  My
> Action class' code needs to look up a key in the appropriate resource file.
> What struts class would I use to do this?  I could just as easily do it the
> other way you suggested but I would like to know if this is possible.
>

I suggest reading the JavaDoc comments about the global constants in
org.apache.struts.action.Action -- you'll find out a lot of stuff about
where Struts stores all of its internal data structures.

If you need access to the message resources from your Action, that's
straightforward as well:

  MessageResources resources = (MessageResources)
    getServlet().getServletContext().getAttribute(Action.MessagesKey +
                                                  appPrefix);
  String text = resources.getMessage("my.key");

If you have more than one message resources defined for your subapp, the
extra ones are stored under whatever attribute name you specified with the
"bundle" attribute.

Of course, if you followed my second suggestion and just passed the key,
instead of the internationalized text (and used <bean:message> in the
destination page), you wouldn't have to do this.



> Thanks,
> Dave

Craig


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message