Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
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, Messages.properties, then the properties file for the french locale can be created in the following format:

 

 

Messages_fr_FR.properties (In the DefaultPropertiesFileName_language_country.properties format)

Messages_fr_FR.properties:

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

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.

faces-config.xml

<application>
       <locale-config>
              <default-locale>en</default-locale>
              <supported-locale>fr_FR</supported-locale>
       </locale-config>

       <resource-bundle>
              <base-name>roseindia.Messages</base-name>
              <var>message</var>
       </resource-bundle>
</application>

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

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%
        javax.faces.context.FacesContext ctx =javax.faces.context.FacesContext.getCurrentInstance( );
        ctx.getViewRoot( ).setLocale(new java.util.Locale("fr", "FR"));
%>


<f:view>
<html>
<head><title></title></head>

<body>
<h:form>
<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}" />
</h:form>
</body>
</html>
</f:view>

Download code for all examples

                          

» View all related tutorials
Related Tags: c file ide orm text date jsf form internationalization time air button io dates format label numbers vi locale key

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.