Share on Google+Share on Google+

Referencing a Localized Message

Customizing your application to support a specific location is known as Localization.

Referencing a Localized Message


Customizing your application to support a specific location is known as Localization. If your application supports locale of ?fr_FR?, then it can present the application for French speaking users (in France). In the same way, ?en_US? locale presents an application for English speaking users (in US).

If you want your application to work in different locale like English, French, German etc. then you would need to replace the output according to the locale. For this you can create many properties files for different locales. A properties file is used to hold locale specific information. This file contains the information as key and value pair (In key=value format). You can store label, button text, messages, dates and times, numbers, currencies etc according to the specific locale.

For example, If you have the properties file for the default locale, for example,, then the properties file for the french locale can be created in the following format: (In the format)

# Sample ResourceBundle properties file
name_text=Entrez votre nom:
greeting_text=Bienvenue dans Roseindia

Now this file can be used when the locale is set for France. Edit the faces-config.xml file. resource-bundle element is used to provide the value to the base name and var. Here "basename" is assigned the value representing the path of bundle file under the classes folder and "var" is assigned a value which will be used further in the jsp pages to reference the key in the properties file.




Now, when the locale is set for France then locale specific information is gathered from the file. For example,

<%@ taglib uri="" prefix="h" %>
<%@ taglib uri="" prefix="f" %>
  javax.faces.context.FacesContext ctx =javax.faces.context.FacesContext.getCurrentInstance( );
  ctx.getViewRoot( ).setLocale(new java.util.Locale("fr", "FR"));


<h1><h:outputText value="#{message.inputname_header}"/></h1>
<h:outputText value="#{message.name_text}"/>
<h:inputText value="#{ResourceBean.personName}" />
<h:commandButton action="welcome" value="#{message.button_text}" />

Download code for all examples


Posted on: December 30, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Referencing a Localized Message  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image