|
Few years back, the sites are only developed using a single language and the developer only create the sites to their specific languages. As the globalization occurs, many frameworks are developed to support the multiple languages at a time. 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. So 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.
- MessageFormat - The java.text.MessageFormat class allows you to replace portions of a message string with arguments specified at run time. This is useful in cases where you are creating a sentence, but the words would appear in a different order in different languages. The placeholder string {0} in the message is replaced by the first runtime argument, {1} is replaced by the second argument, and so on.
- MessageResources - The framework class org.apache.struts.util.MessageResources lets you treat a set of resource bundles like a database, and allows you to request a particular message string for a particular Locale instead of for the default Locale the server itself is running in.
The below example will show the use of Internationalization in Struts.
Note :- The example only displays the text coming from the different properties files. The properties file MessageResource.properties is created with different locale suffix example fr is for France, de for Germany etc.. So the example is only having the MessagesResources.properties and not the whole program. you can download the complete source from the file. You can change the locale in the IE by tools>internet options>General---Languages and check the program.
(1)MessageResources.properties
This is the default properties file. If the locale specific file is not present then struts calls the default properties file.
welcome.text=default Welcome Text
(2) MessageResources_en.properties
welcome.text=English Welcome Text
(3) MessageResources_fr.properties
welcome.text=French Welcome Text
(4) MessageResources_de.properties
welcome.text=German Welcome Text
|