Struts Internationalization (i18n)

Hi Experts,

I am internationalizing a web site - something I have successfully done before but am having problems with the way the languages are being displayed in the browser.

On a JSP page if I paste French text directly into the JSP page, it is displayed correctly in the browser.  If I pull the same string from a UTF-8 property file with struts tag:

<struts-bean:message bundle="content" key="content.landing.captain.01" />

The text is not formatted correctly.  I suspect it is some struts configuration issue, but cannot track it down.  Any suggestions?

Any help greatly appreciated!

Regards,

John
mygreenislandAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Mr_ItConnect With a Mentor Commented:
Properties files in java are loaded using the ISO 8859-1 character encoding. So your accents (é, à, ...) should work without problems (without converting to \u....). But there are characters, like the Euro-sign (¬) that are not in ISO 8859-1 (it is supported ISO 8859-15 however). So for characters, like the Euro-sign, a conversion to \u.... is necessary. That's why it's never bad to run some native2ascii tool.

Anyway, it looks like your browser applies the default character encoding, that is, us-ascii, and loses any international character. Did try to specify a unicode (like UTF-8) content type for your JSP pages? Using unicode is always recommended to prevent problems like you have right now, because unicode is universal character set that includes all the languages character sets. I'm sure it's also supported by your browser.

You can try to add this to your web.xml (ONLY if you use JSP 2.0 and up):

<jsp-config>
      <jsp-property-group>
            <description>Property group for common configuration for all the JSP's</description>
            <url-pattern>*.jsp</url-pattern>
            <page-encoding>UTF-8</page-encoding>
      </jsp-property-group>
</jsp-config>

OR write something like this in all your JSP's:

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page pageEncoding="UTF-8" %>

If that does not work, make sure your JSP pages itself are saved as UTF-8, because that is what you specify in you pageEncoding ;-)
0
 
Mr_ItCommented:
And how is the text exactly displayed?

I don't think it's a struts problem. It might be a problem with your property files itself. I guess you have problems with special characters like é, à, etc... If so, it's because you are editing your propery files using the native character encoding of your OS and running the application elsewhere?

For resource bundles, it's always a good practice to convert all characters to unicode-encoded (\udddd notation) characters before using them in the application: è would become \u00e8, etc...

There's a standard java tool in the JAVA_HOME/bin folder that takes care of this automatically: http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/native2ascii.html. It's very easy to use. You can even run it from your build script. Just read about it to understand the problem.

There are also several plugins for Eclipse and other IDE's for editing resource bundles. Most of them will do the transformation from native to ascii for you (see the plugin preferences for settings).

Anyway, before you take a look at all this, do a manual test first by putting both the è and \u00e8 in your properties file, and see if this is really the problem you are experiencing...


0
 
Mr_ItCommented:
I just saw that you state that your properties file is UTF-8 encoded (and not OS native), so I think this might be indeed the cause of your problems.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Mr_ItCommented:
I meant, then it might not be the cause of your problems, but maybe you are using native encoding while you think you're not. Hey, it's worth a try!

Like I said, converting to ascii is never bad ;-)
0
 
mygreenislandAuthor Commented:
Hi Mr_It,

Thanks for your recommendations- I thought my poor question had been forgotten about ;-)   I am going to research the tools you mentioned- I would not be at all surprised if it is indeed the prop files that are the problem.  One thing though- it seems like you should not have to encode every character?  Do people in France encode their special characters?

I would be interested to learn more about this topic in general.

Thanks,

John
0
 
Mr_ItCommented:
The tool only converts the 'special' characters. Problème would become Probl\u00e8me. The tool also works the other way around.

I have had project where é, à characters etc were displayed correctly. In another everything we had to convert them with the native2ascii tool. Just try to type \u00e8 in your properties file as a quick test and see what it does...
0
 
mygreenislandAuthor Commented:
Hi Mr_It,

Thanks for the suggestions.  I think I am getting closer to the solution, although not necessarily a better  understanding of all the issues at play.

First off- I agree with you- this is not a struts issue but something to do with the format of the file.

I tried the native2ascii utility and it worked without problem.  For example, it would convert the è to \u00e8, etc.  But the strange thing is that the browser would not display the characters correctly- également was replaced with également.

Then I tried something based on another of your suggestions- using a resource bundle plugin tool for Eclipse.  I figured I would create the property file with their tool and assumed that they would set up the file with the correct format, and this actually worked- almost!  Almost all the characters are displaying correctly, but some characters (e.g. presquîle) are being replaced in both Eclipse editor and in browser with a question mark.  Seems strange that it would be OK with some chars but not with all.

I hope that these latest symptoms give you a clue as to what might be happening, because I am running out of things to try ;0)

Thanks,

John
0
 
Mr_ItCommented:
This is funny! To illustrate that character encoding is something that is often overlooked: The EURO sign in and also others in my previous post do not display correctly in my browser  :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.