3

I'm using a resourcebundle to read a properties file based on locale. (Lang_en_US.properties, ..)

The resourcebundle is read as iso-8859-1 (standard?).

ResourceBundle rb= ResourceBundle.getBundle("Lang", locale);

The resourcebundle is then used throughout the Spring/JSF web-application to generate the front-end text.

<h:outputText value="#{msg['message.example']}" />

But I believe this is irrelevant, as debugging shows that the text is already gibberish right after rb getMessage is called.

// returns gibberish:
log.trace(rb.getMessage("l_SampleText"));

2 Answers2

1

I believe you are correct in assuming the resourcebundle is read in as iso-8859-1. Javadoc of Properties class (source)

Are you sure your properties file is saved under the iso-8859-1 format? I believe Notepad++ provides the functionality to at least check the encoding, if not convert it.

Community
  • 1
  • 1
Steven
  • 1,365
  • 2
  • 13
  • 28
0

Since you are using UTF-8 characters that might not be encoded properly in ISO-8859-1, you have 2 options

  1. Use nativetoascii tool to escape the characters in the bundle so that all the chars are read properly

  2. Use Spring's MessageSources's bundle support which supports files in UTF-8 encoding

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • 1
    Thanks for these tips, useful! But wouldn't the UTF-8 characters already be messed up by importing them using iso-8859-1 in the resource bundle? –  Nov 08 '12 at 10:05