You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ho...@netscape.net on 2000/11/17 13:33:20 UTC

i18n, , .jsp

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

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)

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.

Regards
Alf Hogemark

Re: i18n, , .jsp

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
hogemark@netscape.net wrote:

> Ok,, I've tried the new <form:html> (build 22-11-2000)
>
> My comments :
> 1. As it is now, the <form:html> expects an empty body.
> Clearly, this must be wrong ?
> I want
> <form:html>
> <head>
> </head>
> <body>
> </body>
> </form:html>
>
> When I tried this in a jsp page I got the error that <form:html>
> expected an empty body.
>

I just fixed this one -- thanks for the bug report.

>
> 2. As far as I understand from http://www.w3.org/TR/xhtml1/ ,
> the <html> tag should look like this
> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
>
> This means that the <form:html> must also produce xmlns="..." .
>

The "xmlns" value is defined (in the DTD) with a default value corresponding to
the string you cite above.  That's why I chose not to bother generating it.

>
> 3. The attribute xhtml doesn't seem to have any effect.
> <form:html xhtml="true"/>
>
> produces : <html>, and not as I expected <html xml:lang="en">
>

What it should really generate is:

    <html lang="en" xml:lang="en">

But, this cannot happen until there is a Locale object stored in the user's
session in order to make the decision.  Go a few pages into the app and you will
see the language tags being generated.

>
> By the way, the lang attribute is constructed correctly, so that I get
> <html lang="no">
>
> Regards
> Alf Hogemark

Craig



Re: i18n, , .jsp

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Matthias Kerkhoff wrote:

> >> > 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">
>
> Sorry, I think, this is not correct. The HTML spec doesn't mention xmlns=.
>

I went back and changed this after Matthias pointed it out.  There is now an
optional xhtml attribute that you have to set to some value in order to have the
"xml:lang" thing generated.

There's also going to be one more change to <form:html> in tonight's build.  Alf
Hogemark pointed out that I've got the body content set to "empty" in the TLD --
and that is clearly not the write answer.  After tonight, you will be able to
say:

    <form:html>
        ... the contents of your page ...
    </form:html>

like you do with any other tag.

Craig McClanahan



Re[2]: i18n, , .jsp

Posted by Matthias Kerkhoff <ma...@BESToffers.de>.
>> > 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">

Sorry, I think, this is not correct. The HTML spec doesn't mention xmlns=.

Re: i18n, , .jsp

Posted by ho...@netscape.net.
struts-user@jakarta.apache.org wrote:
>
> hogemark@netscape.net wrote:
> 
> >
> > 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">
> >
> 
> I just added a new <form:html/> tag that will generate the "lang" and 
"xml:lang"
> attributes automatically, based on the Locale bean stored in the user's 
session
> (if there is one).  The "xmlns" attribute has a default value in the XHTML 
1.0
> DTD, so there was no need to create this constant value.
> 
> 
> > Alf Hogemark
> 
> Craig McClanahan
> 
> 
> 

Ok,, I've tried the new <form:html> (build 22-11-2000)

My comments :
1. As it is now, the <form:html> expects an empty body.
Clearly, this must be wrong ?
I want
<form:html>
<head>
</head>
<body>
</body>
</form:html>

When I tried this in a jsp page I got the error that <form:html>
expected an empty body.

2. As far as I understand from http://www.w3.org/TR/xhtml1/ ,
the <html> tag should look like this
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 

This means that the <form:html> must also produce xmlns="..." .

3. The attribute xhtml doesn't seem to have any effect.
<form:html xhtml="true"/>

produces : <html>, and not as I expected <html xml:lang="en">

By the way, the lang attribute is constructed correctly, so that I get
<html lang="no">

Regards
Alf Hogemark

Re: i18n, , .jsp

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
hogemark@netscape.net wrote:

>
> 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">
>

I just added a new <form:html/> tag that will generate the "lang" and "xml:lang"
attributes automatically, based on the Locale bean stored in the user's session
(if there is one).  The "xmlns" attribute has a default value in the XHTML 1.0
DTD, so there was no need to create this constant value.


> Alf Hogemark

Craig McClanahan



Re: i18n, , .jsp

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
See intermixed comments below.

hogemark@netscape.net 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