Internationalization is the process of developing a software application so that it can be altered to various languages and regions without modifying the application. Developing an application locale specific increases, the cost of the application, also require lots of maintenance.
Localization is the process of adapting internationalized software for a specific region or country by translating text and adding locale-specific components.
So, it is good to develop an application using the concept of internationalization. It saves time and reduces development cost and require less efforts to maintain it.
Before understanding the term Localization, it is important to understand a concept that is often read along with it, "Internationalization".
Internationalization is the process of developing an application that supports various languages, number formats, currency, date, time and other formats. It is an integral part of any modern multilingual system. There is a very popular abbreviation (perhaps more popular than the real name) for international production - "I18N" because of the 18 characters between 'i' and 'n'.
Modern business systems need to serve people from different regions/ countries of the world or many cultural areas. Different cultural or linguistic regions determine not only the specific meanings of a language but also determine the type of currency, numerical representation, and even variation of date and time.
For example, have a look at the decimal and thousand separators conventions for different countries:
Similarly, the date and time formats are also different. For example:
What's more, we know that there are unique currency symbols for different countries:
Please note that even if some countries have same currency and currency symbol like that of France and Italy, the position of their currency symbol could be different.
Within Java, we have a fantastic feature at our disposal called the Locale class. It allows us to quickly differentiate between cultural locales and format our content appropriately. Similar to I18N, Localization also has its acronym - "I10N" because of the 10 letters between 'I' and 'N'. The main reason for using Locale is that all required local-specific formatting can be accessed without recompilation. The application can handle multiple locales at once, so support for a new language is straightforward.
Localization can also be defined as the process of adapting a product's content to a specific place or language. Translating words is a well-known part of this process, but it is not the only part. Locale practices often include:
Even in countries with the same languages, you can find differences, for example, American English vs. British English.
Benefits of Localization
Let's understand how to implement localization in programming.
Another option is Locale.Builder. Locale.Builder has five set methods that we can use to build an object and at the same time validate those values:
The String representation of the above Locale is fr_CA_POSIX_#Latn.
It is good to know that the 'variant' set may be a bit tricky as there are no legal limits to different values, although the set method requires compliance with BCP-47. If not, it will throw IllformedLocaleException.
In a situation where we need to use a value that does not exceed the guarantee, we may use Locale constructors as they do not validate values.
Importance of Locale Class
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.
Fields of Locale Class
There are the following fields of Java Locale class:
Constructors of the Java Locale Class
There are the following three constructors of the Locale class, as follows:
Methods of the Java Locale Class
There are the following methods used to localize a Java application.
Detects the current default location for this Java Virtual Machine event.
Java Virtual Machine sets the default location during implementation based on the host location. It uses many locale-sensitive methods in an area when there is no explicit location. It can be changed using the setDefault( ) method.
The default locale for this instance of the Java Virtual Machine.
Sets the default location for this Java Virtual Machine event. This does not affect the location of the host.
If there is a security manager, its checkPermission method is called, PropertyPermission (" user.language ", " write ") before the default location is changed.
Java Virtual Machine sets the default location during implementation based on the host location. It uses many sensitive methods in an area when there is no explicit location.
Since changing location can affect many different operating environments, this method should only be used if the caller is ready to reset the locale-sensitive code running within the same Java Virtual machine.
By setting the default location in this way, all the default regions for each Phase are also set to the specified location.
newLocale: the new default locale
SecurityException: if a security manager exists and its checkPermission method doesn't allow the operation.
NullPointerException: if newLocale is null
Returns a list of all two-letter country codes defined in ISO 3166. Can be used to create locales.
Note: The Locale class also supports other country/region codes, such as the UN M.49 3-digit city code. Therefore, the list returned by this method does not contain all valid code that can be used to create a locale.
An array of ISO 3166 two-letter country codes.
It returns a list of all two-letter language codes defined in ISO 639. It can be used to create locales.
Note: ISO 639 is not a stable standard. Some language codes have been changed. The list returned by this function contains both new and old code for languages where the code has changed.
The Locale class also supports language codes up to 8 characters long. Therefore, the list returned by this method does not contain all valid code that can be used to create a locale.
An array of ISO 639 two-letter language codes.
It returns the script for this locale, which must be an empty string or a 4-digit ISO 15924 script code. The first letter is uppercase and the rest are lowercase ( eg "Latin", "Kyrl" ).
The script code, or the empty string if none is defined.
Returns the country/region code for this locale, which should either be the empty string, an uppercase ISO 3166 2-letter code, or a UN M.49 3-digit code.
The country/region code, or the empty string if none is defined.
It returns the string representation of this locale object consisting of language, country, variant, script, and extension as shown below.
toString() method of the Object class.
A string representation of the Locale, for debugging.
Note that the language is always lower case, country is always upper case, script is always title case, and extensions are always lower case. When the locale has neither script nor extensions, the result is the same as in Java 6 and prior.
The function will return the empty string if both the language and country fields are missing, even if the variant, script, or extensions field is present (you can't have a locale with just a variant, the variant must accompany a well-formed language or country code). If script or extensions are present and variant is missing, no underscore is added before the "#".
The behaviour supports debugging and compatibility with older uses for toString where only language, country, and variant fields were expected. Use toLanguageTag() to represent a Locale as a string for exchange purposes.
It returns the three-letter language abbreviation for the given locale. If a language matches a two-letter ISO 6391 code, the corresponding three-letter ISO 6392/T lowercase code is returned. ISO 6392 language codes can be found on the Internet. If the locale specifies a three-letter language, that language is returned as it is. If no language is specified for the locale, an empty string is returned.
A three-letter abbreviation of this locale's language.
MissingResourceException: Throws MissingResourceException if three-letter language abbreviation is not available for this locale.
Returns the three-letter abbreviation for the country of this locale. If a country matches an ISO 31661 alpha2 code, the corresponding ISO 31661 alpha3 code in uppercase is returned. If you do not specify a country for the locale, it will be an empty string. The ISO 3166-1 codes can be found on-line.
A three-letter abbreviation of this locale's country.
Returns the name of the local language that should be displayed to the user. If possible, the restored name is made locally in the default DISPLAY location. For example, if the region says fr_FR and the DISPLAY default location says en_US, getDisplayLanguage( ) returns "French". If the location is en_US and DISPLAY default location says fr_FR, getDisplayLanguage( ) returns "inglais". If the restored name cannot be localized in the DISPLAY default area (assuming there is no Japanese Croatian name), this function uses the English name and uses the ISO code as a last resort. If the location does not specify a language, this function returns an empty character unit.
The name of the display language.
Returns a locale script name suitable for display to the user. If possible, the name is localized to the default DISPLAY locale. If this locale does not specify a script code, it returns an empty string.
The display name of the script code for the current default DISPLAY locale
Returns the country name of a region suitable for display to the user. If possible, the returned name is localized to the default DISPLAY locale. For example, if the locale is fr_FR and the default DISPLAY locale is en_US, then getDisplayCountry() returns "France". If the locale is en_US and the default DISPLAY locale is fr_FR, then getDisplayCountry() returns "EtatsUnis". If the returned name cannot be localized to the default DISPLAY locale (assuming there is no Japanese name for Croatia), this function uses the English name and uses the ISO code as a last resort. If no country is specified for the locale, this function returns an empty string.
The name of the country appropriate to the locale.
Returns the name of the locale variant code suitable for display to the user. If possible, the name is localized to the default DISPLAY locale. If the locale does not specify a variant code, this function returns an empty string.
The name of the display variant code appropriate to the locale.
Returns the name of a locale suitable for display to the user. This will be the value returned by getDisplayLanguage(), getDisplayScript(), getDisplayCountry(), and getDisplayVariant() combined into a single string. Non-empty values are used in sequence with the second and subsequent names in parentheses. Example:
Country depends on the field specified in the locale. If the Language, Script, Country, and Variant fields are empty, this function returns an empty string.
The name of the locale appropriate to display.
Let's implement the localization in an application.
United States English English (United States) USA eng en US