Problem with PropertyResourceBundle

K

kiran

Hi,
I am trying to use PropertyResourceBundle to read a properties file
in my efforts to internationalize my application and display
Hebrew strings. The properties file
ApplicationResources_iw_IL.properties has an entry like
key=<string in Hebrew>
To read this file, I am creating an InputStream on this file and
creating a new PropertyResourceBundle with it as the parameter like
PropertyResourceBundle rb = new PropertyResourceBundle(inputStream);
I am retrieving the value for the key as
rb.getString(key);

The value retrieved works fine if it's in english. To test its working
in Hebrew, I installed Hebrew as one of the input locales on my windows
2000 machine, opened the properties file which is encoded as ISO-8859-1
and typed the value in hebrew using the english keyboard with the
hebrew locale. The entered value looked like Hebrew.

But the problem is that the getString() method returns a gibberish
string and not the one which looks like the one in the properties file.
I am not sure if the inputstream is not able to read the hebrew
characters properly or my setup on the US English windows machine is
wrong. Also, after entering the value in the properties file with the
Hebrew locale, I closed the file and opened it again. The hebrew text
appeared as ?????. Not sure if this
is a part of the problem.

I appreciate if you can provide me some steps in how to create the
intended properties file and then retrieve the string.

Thanks for the help
-Kiran
 
J

John C. Bollinger

kiran said:
Hi,
I am trying to use PropertyResourceBundle to read a properties file
in my efforts to internationalize my application and display
Hebrew strings. The properties file
ApplicationResources_iw_IL.properties has an entry like
key=<string in Hebrew>
To read this file, I am creating an InputStream on this file and
creating a new PropertyResourceBundle with it as the parameter like
PropertyResourceBundle rb = new PropertyResourceBundle(inputStream);
I am retrieving the value for the key as
rb.getString(key);

The value retrieved works fine if it's in english. To test its working
in Hebrew, I installed Hebrew as one of the input locales on my windows
2000 machine, opened the properties file which is encoded as ISO-8859-1

Opened with what program? How does it know the encoding to use?
and typed the value in hebrew using the english keyboard with the
hebrew locale. The entered value looked like Hebrew.

Which has everything to do with your editor and nothing to do with the
file. How do you know that the editor encoded the file with ISO-8859-1
when it saved it? (Hint: it didn't, at least, not correctly.)
But the problem is that the getString() method returns a gibberish
string and not the one which looks like the one in the properties file.

How a string "looks" is a function of the mechanism used to display it,
which is a separate issue from whether or not it contains the characters
you think it should.
I am not sure if the inputstream is not able to read the hebrew
characters properly or my setup on the US English windows machine is
wrong.

InputStreams read bytes, not characters. They don't care about
encodings and can generally be relied upon to accurately read the
sequence of bytes provided by whatever data source they are attached to.
PropertyResourceBundle converts the bytes to characters according to
the ISO-8859-1 charset, by some particular means that is not specified
in the class' contract. It can generally be relied upon to perform the
conversion correctly.

I can't say much about your local setup, but it may be just fine. See
below.
Also, after entering the value in the properties file with the
Hebrew locale, I closed the file and opened it again. The hebrew text
appeared as ?????. Not sure if this
is a part of the problem.

It is a symptom of the problem. Again, I'm not sure what editor you are
using, nor how you are instructing it about what encoding to use to read
and write files. But I do know this: the letters of the Hebrew alphabet
are not among those encoded by ISO-8859-1. (See, for instance,
http://www.utoronto.ca/webdocs/HTMLdocs/NewHTML/iso_table.html.)
That's why I am confident that your editor could not have correctly
encoded the data with ISO-8859-1, and I am certain this is a key aspect
of your problem.

You can employ Java-style Unicode escapes (\uxxxx) to include characters
in Java .properties files that cannot be encoded in ISO-8859-1. It
sounds like you're going to need to leverage that ability.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,216
Messages
2,571,120
Members
47,724
Latest member
Farreach2565

Latest Threads

Top