Using German Umlauts / Umlaute in JSF/JSF2

15 Feb
2010

If you happen to localize your JSF Web-Application to German, you’ll probably have problems displaying German Umlauts ( äÄ, ö Ö, ü Ü, ß) in your page.

How to resolve this? Encode the umlauts with their Unicode code in your message-bundle like this

  1. ä = \u00e4
  2. Ä = \u00c4
  3. ö = \u00f6
  4. Ö =\u00d6
  5. ü = \u00fc
  6. Ü = \u00dc
  7. ß = \u00df

So, e.g. just specify it like this in your bundle.properties

1
homework=Haus\u00fcbung

Specify the bundle itself in your faces-config.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version='1.0' encoding='UTF-8'?>
 
<faces-config version="2.0"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
 
    <application>
        <resource-bundle>
            <base-name>/bundle</base-name>
            <var>bundle</var>
        </resource-bundle>
    </application>
</faces-config>

and use it in your facelets page example.xhtml like this:

1
#{bundle.homework}

or like this

1
<h:outputText value="#{bundle.homework}" />

If you don’t want to convert all the Umlauts in your bundle by hand, simply use javas

1
native2ascii

command to automatically encode the Umlauts in your bundle.properties file.

Update:
I found this unicode chart, which I think is quite useful!

4 Responses to Using German Umlauts / Umlaute in JSF/JSF2

Avatar

Simon

February 16th, 2010 at 09:38

wouldn’t it be easier to use unicode directly. It seems as if you were trying to use unicode escape sequences in a non unicode file. I heard that there are some problems with unicode under windows, but imho thats the way to go.

just my €0.02

Avatar

Shing

February 25th, 2010 at 08:34

Another way to do that is to type the resource bundle in unicode, and then use native2ascii utility in jdk to convert to /uXXXX when building your project. There is a maven2 plugin: native2ascii-maven-plugin

Avatar

Stijn de Witt

May 18th, 2010 at 21:18

Mmmm… I don’t know what to think of this… We store our resources in database-based resource bundles so it has been a long time ago I last tried it with files… but… It would seem *very* strange to me that Sun would demand resource bundles, of all files, specifically meant for internationalization, to be ASCII… Then again Sun has done some strange things in the past.. it’s not impossible! 🙂

I think you should check your bundle files in a text editor that has some nice character encoding features (I suggest Open Source Notepad++) and I think you will see that they are actually stored as ASCII… Try to save them as Unicode/UTF-8 and I bet you can use unicode characters in them directly, without having to escape them.

Avatar

Oleg

August 5th, 2010 at 09:45

Hello Dominic,

Hmm… It was necessary in Struts application. I don’t write Unicode code in resource bundles for my JSF 2 applications. I write directly ä, ö, etc. It works great. You should have in your XHTML pages. Nothing more. Is there really a reason to encode the umlauts?

Best regards.
Oleg.

Comment Form

top