Java Reference
In-Depth Information
should migrate their code to use the new Builder class and the forLan-
guageTag() method.
A Locale.Builder instance has a variety of setter methods that help you con-
figure it to create a valid, BCP 47-compliant Locale instance:
public Locale.BuildersetLanguage(String lan-
guage)
public Locale.BuildersetRegion(String region)
public Locale.BuildersetScript(String script)
Each of these methods throws a java.util.IllFormedLocaleException
if its argument is not a well-formed element of the BCP 47 standard. The language
parameter must be a valid two- or three-letter ISO 639 language identifier. The region
parameter must be a valid two-letter ISO 3166 region code or a three-digit M.49 United
Nations “area” code. Finally, the script parameter must be a valid four-letter ISO 15924
script code.
The Builder lets you configure it to create a specific BCP 47-compliant locale.
Once you set all the configurations, the build() method creates and returns a
Locale instance. Notice that all the setters can be chained together for a single state-
ment. The Builder pattern works by having each configuration method return a ref-
erence to the current instance, on which further configuration methods may be called.
Locale aLocale = new
Builder().setLanguage("fr").setRegion("FR").build();
The BCP 47 document and the standards that comprise it can be found at the fol-
lowing locations:
BCP 47 (language tags): http://www.rfc-editor.org/rfc/
bcp/bcp47.txt
ISO 639 (language identifiers): http://www.loc.gov/standar-
ds/iso639-2/php/code_list.php
ISO 3166 (region identifiers): http://www.iso.org/iso/coun-
try_codes/iso_3166_code_lists/coun-
try_names_and_code_elements.htm
Search WWH ::




Custom Search