Struts Internationalization (i18n)

Posted on 2008-10-12
Last Modified: 2013-11-24
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!


Question by:mygreenisland
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2

Expert Comment

ID: 22795511
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: 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...


Expert Comment

ID: 22795541
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.

Expert Comment

ID: 22795611
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 ;-)
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI


Author Comment

ID: 22795824
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.



Expert Comment

ID: 22799408
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...

Author Comment

ID: 22804547
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)



Accepted Solution

Mr_It earned 500 total points
ID: 22810879
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):

            <description>Property group for common configuration for all the JSP's</description>

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 ;-)

Expert Comment

ID: 22810892
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  :-)

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question