Builder
is used to build instances of ULocale
from values configured by the setters. Unlike the ULocale
constructors, the Builder
checks if a value configured by a setter satisfies the syntax requirements defined by the ULocale
class. A ULocale
object created by a Builder
is well-formed and can be transformed to a well-formed IETF BCP 47 language tag without losing information. Note: The ULocale
class does not provide any syntactic restrictions on variant, while BCP 47 requires each variant subtag to be 5 to 8 alphanumerics or a single numeric followed by 3 alphanumerics. The method setVariant
throws IllformedLocaleException
for a variant that does not satisfy this restriction. If it is necessary to support such a variant, use a ULocale constructor. However, keep in mind that a ULocale
object created this way might lose the variant information when transformed to a BCP 47 language tag.
The following example shows how to create a Locale
object with the Builder
.
ULocale aLocale = new Builder().setLanguage("sr").setScript("Latn").setRegion("RS").build();
Builders can be reused; clear()
resets all fields to their default values.
@see ULocale#toLanguageTag()
@stable ICU 4.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|