Servlets – Internationalization(I18N)
Internationalization(I18N) is the process of designing web applications in such a way that it provides support for various countries, various languages, and various currencies automatically without performing any change in the application is called Internationalization(I18N). It is known as I18N because between I and N; there are 18 characters; that’s why I18N. Internationalization is one of the powerful concepts of java if you are developing an application and want to display messages, currencies, dates, time, etc., according to the specific region or language. Rather deep-diving into the concept, let’s first discuss a few topics which will be helpful for understanding the concepts:
- Internationalization(I18N): it is the task of creating a system that is flexible enough to work in any environment.
- Localization (I10N): It is the process of arranging for a program to run during a specific locale.
- Locale: It represents a selected geographical, political, or cultural region. The string representation of a locale consists of the international standard two-character abbreviation for language and country and an optional variant, separated by underscore (_) characters.
- Web application either retrieves the locale from the request using the getLocale() method or allows the user to explicitly select the locale to get the right strings for a given user.
- An operation that needs a Locale to perform its task is named locale-sensitive and it uses the Locale to tailor information for the user.
- No validity check is performed once you construct a Locale because a Locale object is simply an identifier for a neighborhood.
- getCountry(): It returns the country/region code in upper case for this locale in ISO3166 2-letter format.
- getDisplayCountry(): It returns the name for the locale’s country which is appropriate for display to the user.
- getLanguage(): It returns the language code in lower case for this locale in ISO 639 format.
- getDisplayLanguage(): It returns the name for the locale’s language that is appropriate for display to the user.
- getISO3Country(): It returns a three-letter abbreviation for this locale’s country.
- getISO3Language(): It returns a three-letter abbreviation for this locale’s language.
This example shows how you display a language and associated country for a request
- A servlet outputs a page written in a Western European language such as English, Spanish, German, French, Italian, Dutch, Norwegian, Finnish, or Swedish. Notice the utilization of the special characters “ñ” and “¡”. Characters like these, while scarce in English, are prevalent in Western European languages. Servlets have two ways to get these characters: with HTML character entities or Unicode escape sequences.
- The ability for specific sequences of characters in an HTML page to be displayed as a single character. The sequences, called character entities, begin with an ampersand (&) and end with a semi-colon (;). Character entities can either be named or numbered.
- The Unicode Worldwide Escape Sequences is a character coding system designed to support the interchange, processing, and display of the written texts of the diverse languages of the modern world. In addition, it supports classical and historical texts of the many written languages.
Locale Specific Dates
You can use the java.text.DateFormat class and its static getDateTimeInstance() method to format date and time specific to locale. Following is the example which shows how to format dates specific to a given locale −