See intermixed comments below.
[EMAIL PROTECTED] wrote:
> I've made two ResourceBundles
> One TestAppResource.properties (containg English text) and one
> TestAppResource_no.properties. (Norwegian)
>
> In the first page the user sees, index.jsp, I have
> <bean:message key="title.welcome"/>
>
> The English text comes up, no matter what the "Language" setting is set to
> in Netscape.
> Note that there is no form "connected" to this index.jsp, it's just an
> jsp page producing HTML.
>
> However, I have mainmenu.jsp page, which also contains <bean:message>,
> and this prodouces the text for the correct langauge.
>
> The documentation for <bean:message> says :
> The name of the session scope bean under which our currently selected Locale
> object is stored. If not specified, the default name (the value of the
> Action.LOCALE_KEY constant string) is used.
>
> 1. Does this mean that the Locale is not set correctly before an Action has
> been created / called ?
> After reading some more docs before sending this mail, I assume that I
> may need to set the locale parameter to true for the ActionServlet in
> the web.xml file. I will try this
>
Which version of Struts are you using? For 0.5, you have to create the Locale
object yourself, or it will use the system default locale for message lookups.
With Struts 1.0, you have the additional option to set the following
initialization parameter on the controller servlet in your web.xml file:
<init-param>
<param-name>locale</param-name>
<param-value>true</param-value>
</init-param>
and the Struts controller servlet will create a Locale object in the user's
session, if there is not one present already, based on the HTTP headers included
with the request.
Note that this still only helps if the request was funnelled through the
controller servlet. That means the initial welcome page of an application will
generally be presented in the server's default locale, unless you take some
special measures to select a locale in that page itself.
>
> 2. If I have a message main.welcome=Welcome {0},
> and I want to get the {0} text from the bean User via a call to getUser(),
> how would the <bean:message> look like ?
> <bean:message key="main.welcome" arg0="?????????"/>
> I see there is a <bean:parameter>, but don't understand how to use it.
> (I'm a novice in JSP as well)
>
You can use a JSP "runtime expression" to set things like this dynamically:
<bean:message key="main.welcome"
arg0="<%= user.getName() %>" />
assuming "user" is a bean you've defined previously with a <jsp:useBean id="user">
tag.
>
> 3. The XHTML and HTML4.0 standard says that there should be an attribute
> on the <html> tag specifying the language, a la
> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
>
> How do I construct the value of the xml:lang and lang attributes dynamically ?
> That is :
> a) how do I get hold of the language, even assuming no Action
> has yet been called ?
> b) how do I set the value of the attribute, this is probably the same
> question as 2.
>
That's a good question. It would probably be useful to create a Struts tag that
renders the appropriate <html> tag for you, based on the current locale settings.
In the mean time, you can use runtime expressions as shown in the example above.
>
> Regards
> Alf Hogemark
Craig