Localization is the customization of a software for a particular region. This usually doesn't require coding, because any locale-sensitive object in Java relay on the default locale set by the Virtual Machine. However you may still need to change locale yourself, programmatically, by creating a Locale object and passing it to locale-sensitive objects.
There are three reasons to use localization:
A locale is represented by the object Locale.
Locale locale = new Locale("en", "US");
Here's possible to define five information:
For example in "ja_JP_JP_#u-ca-japanese": ja is the language, JP the country, JP the variant and u-ca-japanese the extension.
You can create a Locale object in four different ways:
1) Constructor:
Locale locale = new Locale("en", "CA");
2) Builder:
Locale locale = new Locale.Builder().setLanguage("it").setRegion("IT").build();
Differently from (1) and (3) checks also the syntax.
3) Factory method:
Locale locale = Locale.forLanguageTag("fr-FR");
4) Constant:
Locale locale = Locale.JAPAN;
Here's an example on how we can assign a particular Locale to a locale-sensitive object like NumberFormat:
NumberFormat nf = NumberFormat.getInstance(Locale.FRANCE); System.out.println(nf.format(15.46f));
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.