You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pierre Métras <ge...@sympatico.ca> on 2000/09/28 16:54:44 UTC

i18n and other minor problems...

Hi all,

Now that my prototype is becoming full struts compliant, I encounters some
problems minor problems during integration.

JavaScript
----------
IE 5 and Netscape 4 allow to have "onMouseOver" and other JavaScript
attributes on the <link> tag (though HTML 4.0 doesn't support it). Is it
possible to make linkTag class inherit from BaseHandlerTag to add these
attributes?


Internationalization
-------------------
My application must be i18n aware, and now problems are harder to solve
because struts is not a complete i18n-MVC framework, but we can try to
correct that. Here are a few ideas.

Major rule: split totaly text information from presentation, to obtain an
i18n-MVC.
        M: message resource file
        V: HTML (or other) form
        C: struts tags and utilities.


[1] No HTML in messages resource files, in case you need to port your
application to another viewing system (for instance WML).
Sometimes, basic formating is necessary in messages, like line break or non
breaking space. I have written a function that substitute "\n" for "<P>",
"\r" for "<BR>", "\b" for "&nbsp;".
This function is also responsible for translating special characters like <
for "&lt;" or é for "&eacute;".
Presently, the translation process from the message files is done at
run-time but it would be smarter to pre-process once all messages that will
be used for HTML generation, once for those used in JavaScript, once for
WML...


[2] Add other tags to struts to allow retrieving localized text.
For instance, create a new <struts:img> that will fetch the "alt" attribute
value from the message resource file.
This behavior is also needed for the "title", "value" and "accessKey" of
<input> tags, "summary" of <table>, "abbr" of <th>...

Is there a better way than redefine all tags involving text attributes?


[3] Precise in the tag how the localized text should be escaped and
formatted.
If you want to be able to print a localized "see you" on your form, and you
use <struts:message key="see.you" />, you should obtain "&agrave;
bient&ocirc;t" to print it in French in the HTML form, but "à bientôt" if
you want to use it in a JavaScript alert() function, with quotes escaped (\'
and \").

This can be done with a new attribute "format" in all tags involving text
localization, with allowed values "html", "java"...

Some examples, using the <message> tag in French, to print "Meteo" and
"today" on two lines:
In the resource file:
        meteo.today=Météo\nAujourd'hui

    <message key="meteo.today" format="html" />
        "M&eacute;t&eacute;o<P>Aujourd'hui"

    <message key="meteo.today" />
        "Météo\nAujourd'hui"

    <message key="meteo.today" format="java" />
        "Météo\nAujourd\'hui"


Why create all this? Majority of applications will support only one
language.
The answer is the same as for "Why put all my application fowards in
action.xml?".

Are there others concerned by i18n support in struts? And how do you solve
your problems?

Pierre Métras


PS: Seems yesterday was a good day for struts users! No question about
weblogic... ;-))