• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

Implement Internationalization and Localization in JSF

July 24, 2008 //  by Krishna Srinivasan

Internationalization and Localization are important features for an web based application. Internationalization is implementing the features in your application to support multiple languages. Localization is creating text in a specific language that is presented through an internationalized application

also read:

  • Introduction to JSF
  • JSF Interview Questions
  • Request Processing Lifecycle phases in JSF

The following example program demonstrates very simple program for implementing this concepts. if you look into the faces-config.xml file,locale-config element is used for specifying the default locale and supported locale information. In this sample application we have provided default as English and supported as French.

Use resource-bundle element to specify the name of the properties file to be used. For example if you create a resource bundle name as Messages, then all the language letters will be suffixed with the file name.In our case French locale is named as “Messages_fr”.The default will be “en”, it is not required to specify explicitly.

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
    <body>
        <f:view>
            <h:form>
                <h:commandButton value="#{msg.cancel}" action="fail"/>
                <h:commandButton value="#{msg.submit}" action="success"/>
            </h:form>
        </f:view>
    </body>
</html>

faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2"
    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_1_2.xsd">
    <application>
        <locale-config>
            <default-locale>en</default-locale>
            <supported-locale>fr</supported-locale>
            <supported-locale>de</supported-locale>
        </locale-config>
        <resource-bundle>
            <base-name>javabeat.net.messages.Messages</base-name>
            <var>msg</var>
        </resource-bundle>
    </application>
</faces-config>

Messages.properties

cancel=Cancel
submit=Submit

Messages_fr.properties

cancel=annuler
submit=envoyer
 

Category: JSFTag: Internationalization

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Chain Of Responsibility Pattern In Java
Next Post: Writing simple ANT build script »

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

How to Write Comparators as Lambda Expressions in Java

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact