2

I am using GWT. i implemented internationalization to support spanish language. but spanish chars are not displayed propertly. Ex: Teléfono Buscar is displayed as . enter image description here(see some junk char after Tel). i am using IE browser.

Do i need to configure any further settings? Thanks!

user1016403
  • 12,151
  • 35
  • 108
  • 137

2 Answers2

2

I suspect this may be due to the fact that your editor isn't using UTF-8 encoding.

If you're using Eclipse, you can configure it to use UTF-8 for *.properties by going to Window > Preferences > General > Content Types.

Just make sure you change the Default encoding value to UTF-8 as shown below.

enter image description here

There will be a similar setting for any text editor, including vi.

adarshr
  • 61,315
  • 23
  • 138
  • 167
1

Since your strings are coming from a properties file, your ResourceBundle is probably an instance of PropertyResourceBundle, which creates an empty instance of java.util.Properties and then populates the instance by loading the properties file via one of the "load" methods. PropertyResourceBundle has two constructors, one which takes an InputStream and one which takes a Reader. The constructors simply call the corresponding "load" method.

Note that the "load" method that takes an InputStream assumes the character encoding of the properties file is ISO 8859-1 (Latin1). You can solve this problem in two ways:

  1. Ensure the property constructor of PropertyResourceBundle is being called, the one that takes a Reader. Construct the reader using the appropriate character encoding.
  2. Use Unicode escapes (\uxxxx) to encode non-ASCII characters in the properties file.
Nathan Ryan
  • 12,893
  • 4
  • 26
  • 37
  • Thanks for your reply. Reading values from properties file is simple for us we are not using any propertyresourcebundle. gwt itself creates interfaces for each properties file. we just call the interface and access the values from properties file. – user1016403 May 30 '12 at 11:24
  • If you don't have control over how the resource bundle is instantiated, the easy solution then is to use Unicode escapes in the properties file. – Nathan Ryan May 30 '12 at 11:25
  • Unicode escapes make the files unreadable by humans if the only languages supported are English and other Latin-based languages such as es, fr, de, etc. Prefer unicode escapes only for Chinese, Korean, Arabic etc. – adarshr May 30 '12 at 11:26
  • Please can you give me an example. consider the string Teléfono Buscar? – user1016403 May 30 '12 at 11:27
  • @user1016403: The Unicode value for é is 0x39 (U+0039, in the Unicode nomenclature). Replace the `é` with the characters `\u0039`. You can find other values at unicode.org. Word of warning, though: As adarshr pointed out, lots of Unicode escapes can severely hinder the readability of your properties file. – Nathan Ryan May 30 '12 at 11:34