Jsp Tutorial Home

Jsp Home

JSP Resources

Community

Site

Internationalization in JSP application

text zoom

Few years back, the sites were developed using a single language and the developer used to create the sites to their specific languages. As the globalization occured, many frameworks have developed to support the multiple languages at a time. Now this can be achieved by having the multi language text in key/value pair and at runtime the text is read from the key as per the language required. This multilingual support is known as Internationalization. Internationalization is defined as the process of designing an application so that it can be adapted to various languages and regions without engineering changes.


The following classes are used to implement Internationalization to any site.



  • Locale - The fundamental Java class that supports internationalization is Locale . Each Locale represents a particular choice of country and language, and also a set of formatting assumptions for things like numbers and dates.

  • ResourceBundle - The java.util.ResourceBundle class provides the fundamental tools for supporting messages in multiple languages.

  • PropertyResourceBundle - One of the standard implementations of Resource Bundle allows you to define resources using the same "name=value" syntax used to initialize properties files. This is very convenient for preparing resource bundles with messages that are used in a web application, because these messages are generally text oriented.


Note:- The fmt is the jstl tag library used to implement the internationalization in JSP. The below example will tell you "how to use the fmt taglib in the application". The example displays the text coming from the different properties files. The properties file lables.properties is created with different locale suffix example en is for english, de for Germany etc. We have hello key in both the files. hello=This is german File in de file and hello=This is english File in english file.


Example JSP file Internationalization.jsp file .


<%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld"%>
<fmt:setLocale
value="de" scope="session"/>
<fmt:bundle
basename="com.visualbuilder.labels">
    <fmt:message>
    hello
    </fmt:message>
</fmt:bundle>

Output:-


The file will display "This is german File" and if the locale is changed to en then it will display the "This is english file."

                    

Copyright © 2010 VisualBuilder. All rights reserved