Este conteúdo não está disponível no idioma selecionado.

Chapter 16. Internationalization, localization and themes


There are several stages required to internationalize and localize your application.

Note

Internationalization features are available only in the JSF context.

16.1. Internationalizing your application

A Java EE 5 application involves many components, all of which must be configured properly to localize your application.
Before you begin, ensure that your database server and client use the correct character encoding for your locale. Normally, you will want UTF-8 encoding. (Setting the correct encoding falls outside the scope of this tutorial.)

16.1.1. Application server configuration

You will need to configure the Tomcat connector to ensure that the application server receives the request parameters from client requests in the correct encoding. Add the URIEncoding="UTF-8" attribute to the connector configuration in $JBOSS_HOME/server/$PROFILE/deploy/jboss-web.deployer/server.xml:
<Connector port="8080" URIEncoding="UTF-8"/>
Copy to Clipboard Toggle word wrap
Alternatively, you can tell JBoss Enterprise Application Platform that the correct encoding for the request parameters will be taken from the request:
<Connector port="8080" useBodyEncodingForURI="true"/>
Copy to Clipboard Toggle word wrap

16.1.2. Translated application strings

You will also need localized strings for all of the messages in your application (for example, field labels on your views). First, ensure that your resource bundle is encoded with the desired character encoding. ASCII is used by default. Although ASCII is enough for many languages, it does not provide characters for all languages.
Resource bundles must either be created in ASCII, or use Unicode escape codes to represent Unicode characters. Since you do not compile a property file to byte code, there is no way to tell JVM which character set to use. Therefore, you must use either ASCII characters or escape characters not in the ASCII character set. You can represent a Unicode character in any Java file with \uXXXX, where XXXX is the hexadecimal representation of the character.
You can write your translation of labels (Section 16.3, “Labels”) to your message resource bundle in the native coding. The native2ascii tool provided in the JDK lets you convert the contents of a file written in your native encoding into one that represents non-ASCII characters as Unicode escape sequences.
Usage of this tool is described here for Java 6. For example, to convert a file from UTF-8:
 $ native2ascii -encoding UTF-8 messages_cs.properties > messages_cs_escaped.properties 
Copy to Clipboard Toggle word wrap

16.1.3. Other encoding settings

We need to make sure that the view displays your localized data and messages in the correct character set, and that any data submitted uses the correct encoding.
Use the <f:view locale="cs_CZ"/> tag to set the display character encoding. (Note that this locale value sets JSF to use the Czech locale.) If you want to embed localized strings in the XML, you may want to change the XML document's encoding. To do so, alter the encoding attribute value in the XML declaration <?xml version="1.0" encoding="UTF-8"?>.
JSF/Facelets should submit any requests with the specified character encoding, but to ensure that requests that do not specify an encoding are submitted, you can force the request encoding using a servlet filter. Configure this in components.xml:
<web:character-encoding-filter encoding="UTF-8" override-client="true" 
     url-pattern="*.seam" />
Copy to Clipboard Toggle word wrap
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2026 Red Hat
Voltar ao topo