You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Scott Purcell <sp...@vertisinc.com> on 2005/01/20 21:51:29 UTC

message tag, resource bundle

Hello,
 
I am having trouble understanding how the message tag and the resource bundle work together.
 
Let me try and summarize. I have gone through the O'Reilly book and I see how the resoruce bundle and the bean:message tag work, but would like a little more in-depth understanding:
 
In a jsp I have a link like this:
  <title><bean:message key="title.login"/></title>
And when I look at the struts-config.xml I have this entry
<struts-config>
 
  <controller 
    contentType="text/html;charset=UTF-8"
    debug="3"
    locale="true"
    nocache="true"/> 
  
  <message-resources parameter="globalResources" null="false"/>
 

</struts-config>
 
And when I look around I find the "globalResources.properties" file under /WEB-INF/classes
 
And I see how the above call brings in the value of title.login.
 
All that makes sense. So my question is as follows:
1) Why does the globalResources.properties live under /WEB-INF/classes? Is there a way to configure this differently?
2) The book says the following:
    The message tag is one of the most widely used tags within teh Struts tab libraries. It recives an internationalized message for the specified locale, using the specified message key, and writes it to the output stream.
I could use some clarification as to what that statement means.
I interpret it, as I can use a .properties file for different messages??
 
If someone who understands this better could give me a hand, I would appreciate.
 
Sincerely,
Scott
 

Re: message tag, resource bundle

Posted by Anthony Hong <an...@gmail.com>.
Struts message mechanism use Java ResourceBundle to load language
bundle resource, it's follow Java ResourceBundle's rule.
I would like to recommend you to look at Java's Internationalization technic
http://java.sun.com/docs/books/tutorial/i18n/resbundle/index.html

Struts offer configuration for resource bundle and make it easy for useing.

1.You also could put other place, but make sure your class load could find it.
2. You can have more thant message-resource element in configuration file.
and for other bundle, you have to put key attribute
<message-resources parameter="com.maveo.action.language.AdminSiteMain"
key="mainResource" null="false"/>

where you can use it as 
<bean:message key="title.login" bundle="mainResource"/>


On Thu, 20 Jan 2005 14:51:29 -0600, Scott Purcell
<sp...@vertisinc.com> wrote:
> Hello,
> 
> I am having trouble understanding how the message tag and the resource bundle work together.
> 
> Let me try and summarize. I have gone through the O'Reilly book and I see how the resoruce bundle and the bean:message tag work, but would like a little more in-depth understanding:
> 
> In a jsp I have a link like this:
>  <title><bean:message key="title.login"/></title>
> And when I look at the struts-config.xml I have this entry
> <struts-config>
> 
>  <controller
>    contentType="text/html;charset=UTF-8"
>    debug="3"
>    locale="true"
>    nocache="true"/>
> 
>  <message-resources parameter="globalResources" null="false"/>
> 
> </struts-config>
> 
> And when I look around I find the "globalResources.properties" file under /WEB-INF/classes
> 
> And I see how the above call brings in the value of title.login.
> 
> All that makes sense. So my question is as follows:
> 1) Why does the globalResources.properties live under /WEB-INF/classes? Is there a way to configure this differently?
> 2) The book says the following:
>    The message tag is one of the most widely used tags within teh Struts tab libraries. It recives an internationalized message for the specified locale, using the specified message key, and writes it to the output stream.
> I could use some clarification as to what that statement means.
> I interpret it, as I can use a .properties file for different messages??
> 
> If someone who understands this better could give me a hand, I would appreciate.
> 
> Sincerely,
> Scott
> 
> 


-- 

Anthony Hong

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


Re: message tag, resource bundle

Posted by Corey Probst <cp...@gmail.com>.
> 1) Why does the globalResources.properties live under /WEB-INF/classes? Is there a way to configure this differently?

I'm not an expert but I'll try to help...
The properties file is loaded using a ClassLoader.  So the short
answer is that the /WEB-INF/classes folder is on the class path by
default.

> 2) The book says the following:
>    The message tag is one of the most widely used tags within teh Struts tab libraries. It recives an internationalized message for the specified locale, using the specified message key, and writes it to the output stream.
> I could use some clarification as to what that statement means.
> I interpret it, as I can use a .properties file for different messages??

You can define different properties files for different locales.  This
way, you externalize these strings.  The file that gets loaded depends
on the locale that is set.  You could create a
globalResources_es.properties file for Spain.  This would contain all
of your messages in Spanish.  Then when the Locale was set to Spain
these messages would be loaded instead of your default messages.

-- Corey

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