You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kumar V Kadiyala <kk...@us.ibm.com> on 2004/10/23 00:15:29 UTC

MessageResources native to ascii conversion

Hi,

I have a struts based application which supports several locales (italian, 
french, korean etc). There are different .properties files to accomplish 
this. The respective .properties files of each language were translated 
recently.
When I bring up the app in Korean, it seems like the strings are not 
displayed correctly. I went thru some web sites and found out that I had 
to convert the Korean translated file to ascii. I tried to use 
"native2ascii" tool shipped with Java1.4.2 and was getting back a 
sun.io.MalformedException. I used EUC-KR as the encoding. Am I doing 
something wrong here?
When I bring up the GUI in French, it seemed like the strings were being 
displayed correctly, but I can't tell as I don't speak French. Do I have 
to do a native2ascii conversion on the French and Italian files too? If 
yes, what encoding should I use?

Help appreciated,
Kumar

Re: MessageResources native to ascii conversion

Posted by Craig McClanahan <cr...@gmail.com>.
Struts uses java.util.ResourceBundle instances inside it's
MessageResources implementation.  In particular, the most common
mechanism is to implicitly use PropertyResourceBundle instances that
take a properties file and turn it into a ResourceBundle.  Therefore,
you must follow all the rules described in the Javadocs for the
java.util.Properties and java.util.PropertyResourceBundle classes with
regard to encoding.

More information interspersed below, but please check out the Javadocs
for these classes.

There's also a ton of useful information about internationalizing and
localizing Java apps in general in the Internationalization trail of
the Java Language Tutorial.  Here's the welcome page for it:

  http://java.sun.com/docs/books/tutorial/i18n/index.html

On Fri, 22 Oct 2004 16:15:29 -0600, Kumar V Kadiyala
<kk...@us.ibm.com> wrote:
> Hi,
> 
> I have a struts based application which supports several locales (italian,
> french, korean etc). There are different .properties files to accomplish
> this. The respective .properties files of each language were translated
> recently.

As stated in the Javadocs, a properties file *must* be encoded in
ASCII.  Therefore, if you edit your source properties file in EUC_KR,
you will need to translate it into ascii before packaging the file
into your webapp.  The simplest way is the "native2ascii" tool:

  native2ascii -encoding EUC_KR < src/mycompany/mypackage/MyBundle.properties \
    > build/WEB-INF/classes/mycompany/mypackage/MyBundle.properties

As others have pointed out, there's a convenient Ant task for this
purpose, if you are using Ant in your build environment.

> When I bring up the app in Korean, it seems like the strings are not
> displayed correctly. I went thru some web sites and found out that I had
> to convert the Korean translated file to ascii. I tried to use
> "native2ascii" tool shipped with Java1.4.2 and was getting back a
> sun.io.MalformedException. I used EUC-KR as the encoding. Am I doing
> something wrong here?

The EUC_KR encoding requires the "$JAVA_HOME/lib/charsets.jar" to be
on the classpath, because it's not built in to the standard runtime. 
See <http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html>
for more info.

> When I bring up the GUI in French, it seemed like the strings were being
> displayed correctly, but I can't tell as I don't speak French. Do I have
> to do a native2ascii conversion on the French and Italian files too?

If you do not happen to use any accented characters, it will work ...
but that is pretty unlikely.  Therefore, you should be performing the
transformation on these files too.

> If
> yes, what encoding should I use?
> 

Whatever encoding is supported by your editing tools (and by
native2ascii) is fine ... I personally recommend UTF-8 for everything,
so that I don't have to remember which encoding to use on which file.

> Help appreciated,
> Kumar
> 

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org