Internationalization is also abbreviated as I18N because there are total 18 characters between the first letter 'I' and the last letter 'N'.
Internationalization is a mechanism to create such an application that can be adapted to different languages and regions.
Internationalization is one of the powerful concept of java if you are developing an application and want to display messages, currencies, date, time etc. according to the specific region or language.
Localization is also abbreviated as I10N because there are total 10 characters between the first letter 'L' and last letter 'N'. Localization is the mechanism to create such an application that can be adapted to a specific language and region by adding locale-specific text and component.
Do You Know ?Before starting the internationalization, Let's first understand what are the informations that differ from one region to another. There is the list of culturally dependent data:
An object of Locale class represents a geographical or cultural region. This object can be used to get the locale specific information such as country name, language, variant etc.
There are fields of Locale class:
There are three constructors of Locale class.They are as follows:
There are given commonly used methods of Locale class.
In this example, we are displaying the informations of the default locale. If you want to get the informations about any specific locale, comment the first line statement and uncomment the second line statement in the main method.
import java.util.*; public class LocaleExample { public static void main(String[] args) { Locale locale=Locale.getDefault(); //Locale locale=new Locale("fr","fr");//for the specific locale System.out.println(locale.getDisplayCountry()); System.out.println(locale.getDisplayLanguage()); System.out.println(locale.getDisplayName()); System.out.println(locale.getISO3Country()); System.out.println(locale.getISO3Language()); System.out.println(locale.getLanguage()); System.out.println(locale.getCountry()); } }
In this example, we are displaying english language in different language. Let's see how english is written in french and spanish languages.
import java.util.*; public class LocaleExample2 { public static void main(String[] args) { Locale enLocale = new Locale("en", "US"); Locale frLocale = new Locale("fr", "FR"); Locale esLocale = new Locale("es", "ES"); System.out.println("English language name (default): " + enLocale.getDisplayLanguage()); System.out.println("English language name in French: " + enLocale.getDisplayLanguage(frLocale)); System.out.println("English language name in spanish: " + enLocale.getDisplayLanguage(esLocale)); } }
In this example, we are displaying the display lanuage of many locales.
import java.util.*; public class LocaleEx { public static void main(String[] args) { Locale[] locales = { new Locale("en", "US"), new Locale("es", "ES"), new Locale("it", "IT") }; for (int i=0; i< locales.length; i++) { String displayLanguage = locales[i].getDisplayLanguage(locales[i]); System.out.println(locales[i].toString() + ": " + displayLanguage); } } }