|
FlexDoc/Javadoc 2.0 Demo Java Doc |
Note: The Locale 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 Locale constructor. However, keep in mind that a Locale 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.
Locale aLocale = new Builder().setLanguage("sr").setScript("Latn").setRegion("RS").build();
Builders can be reused; clear() resets all fields to their default values.
Constructor Summary |
||
Builder()
Constructs an empty Builder.
|
Method Summary |
||
addUnicodeLocaleAttribute(String attribute)
Adds a unicode locale attribute, if not already present, otherwise
has no effect.
|
||
build()
Returns an instance of Locale created from the fields set
on this builder.
|
||
clear()
Resets the builder to its initial, empty state.
|
||
Resets the extensions to their initial, empty state.
|
||
removeUnicodeLocaleAttribute(String attribute)
Removes a unicode locale attribute, if present, otherwise has no
effect.
|
||
setExtension(char key, String value)
Sets the extension for the given key.
|
||
setLanguage(String language)
Sets the language.
|
||
setLanguageTag(String languageTag)
Resets the Builder to match the provided IETF BCP 47
language tag.
|
||
Resets the Builder to match the provided
locale.
|
||
Sets the region.
|
||
Sets the script.
|
||
Sets the Unicode locale keyword type for the given key.
|
||
setVariant(String variant)
Sets the variant.
|
Methods inherited from class java.lang.Object |
public Builder |
() |
public Locale.Builder setLocale |
(Locale locale) |
All fields of the locale must be well-formed, see Locale.
Locales with any ill-formed fields cause IllformedLocaleException to be thrown, except for the following three cases which are accepted for compatibility reasons:
public Locale.Builder setLanguageTag |
(String languageTag) |
public Locale.Builder setLanguage |
(String language) |
The typical language value is a two or three-letter language code as defined in ISO639.
public Locale.Builder setScript |
(String script) |
The typical script value is a four-letter script code as defined by ISO 15924.
public Locale.Builder setRegion |
(String region) |
The typical region value is a two-letter ISO 3166 code or a three-digit UN M.49 area code.
The country value in the Locale created by the Builder is always normalized to upper case.
public Locale.Builder setVariant |
(String variant) |
Note: This method checks if variant satisfies the IETF BCP 47 variant subtag's syntax requirements, and normalizes the value to lowercase letters. However, the Locale class does not impose any syntactic restriction on variant, and the variant value in Locale is case sensitive. To set such a variant, use a Locale constructor.
public Locale.Builder setExtension |
(char key, String value) |
Note: The key UNICODE_LOCALE_EXTENSION ('u') is used for the Unicode locale extension. Setting a value for this key replaces any existing Unicode locale key/type pairs with those defined in the extension.
Note: The key PRIVATE_USE_EXTENSION ('x') is used for the private use code. To be well-formed, the value for this key needs only to have subtags of one to eight alphanumeric characters, not two to eight as in the general case.
public Locale.Builder setUnicodeLocaleKeyword |
Keys and types are converted to lower case.
Note:Setting the 'u' extension via setExtension(char, String) replaces all Unicode locale keywords with those defined in the extension.
public Locale.Builder addUnicodeLocaleAttribute |
(String attribute) |
public Locale.Builder removeUnicodeLocaleAttribute |
(String attribute) |
Attribute comparison for removal is case-insensitive.
public Locale.Builder clear |
() |
public Locale.Builder clearExtensions |
() |
public Locale build |
() |
This applies the conversions listed in Locale.forLanguageTag(String) when constructing a Locale. (Legacy tags are handled in setLanguageTag(String).)
|
FlexDoc/Javadoc 2.0 Demo Java Doc |