pub struct Locale {
pub language_code: String,
pub script_code: Option<String>,
pub country_code: Option<String>,
}Expand description
An identifier used to select a user’s language and formatting preferences.
This represents a Unicode Language Identifier (i.e. without Locale extensions), except variants are not supported.
Locales are canonicalized according to the “preferred value” entries in the
IANA Language Subtag Registry.
For example, const Locale('he') and const Locale('iw') are equal and both have the
language_code he, because iw is a deprecated language subtag
that was replaced by the subtag he.
See also:
Localizations, which provides localized resources to the widget tree.
Fields§
§language_code: StringThe primary language subtag for the locale.
This must not be null. It may be ‘und’, representing ‘undefined’.
This is expected to be string registered in the IANA Language Subtag Registry with the type “language”. The string specified must match the case of the string in the registry.
Language subtags that are deprecated in the registry and have a preferred
code are changed to their preferred code. For example, const Locale('he') and const Locale('iw') are equal, and both have the
language_code he, because iw is a deprecated language subtag that was
replaced by the subtag he.
This must be a valid Unicode Language subtag as listed in Unicode CLDR supplemental data.
See also:
Locale::from_subtags, which describes the conventions for creatingLocaleobjects.
script_code: Option<String>The script subtag for the locale.
This may be null, indicating that there is no specified script subtag.
This must be a valid Unicode Language Identifier script subtag as listed in Unicode CLDR supplemental data.
See also:
Locale::from_subtags, which describes the conventions for creatingLocaleobjects.
country_code: Option<String>The region subtag for the locale.
This may be null, indicating that there is no specified region subtag.
This is expected to be string registered in the IANA Language Subtag Registry with the type “region”. The string specified must match the case of the string in the registry.
Region subtags that are deprecated in the registry and have a preferred
code are changed to their preferred code. For example, const Locale('de', 'DE') and const Locale('de', 'DD') are equal, and both have the
country_code DE, because DD is a deprecated language subtag that was
replaced by the subtag DE.
See also:
Locale::from_subtags, which describes the conventions for creatingLocaleobjects.
Implementations§
Source§impl Locale
impl Locale
Sourcepub fn new(language_code: impl Into<String>) -> Locale
pub fn new(language_code: impl Into<String>) -> Locale
Creates a new Locale object. The first argument is the primary language subtag, the second is the region (also referred to as ‘country’) subtag.
For example:
let swiss_french = Locale::new("fr").country_code("CH");
let canadian_french = Locale::new("fr").country_code("CA");The primary language subtag must not be null. The region subtag is optional.
When there is no region/country subtag, the parameter should be omitted or set
to None instead of an empty string.
The subtag values are case sensitive and must be one of the valid subtags according to CLDR supplemental data: language, region. The primary language subtag must be at least two and at most eight lowercase letters, but not four letters. The region subtag must be two uppercase letters or three digits. See the Unicode Language Identifier specification.
Validity is not checked by default, but some methods may throw away invalid data.
Creates a new Locale object from its language, script, and region subtags,
each optional. The language defaults to und.
The keyword arguments specify the subtags of the Locale.
The subtag values are case sensitive and must be valid subtags according to
CLDR supplemental data:
language,
script and
region for
each of language_code, script_code and
country_code respectively.
The country_code subtag is optional. When there is no
country subtag, the parameter should be omitted instead of using an empty string.
Validity is not checked by default, but some methods may throw away invalid data.
Sourcepub fn language_code(self, language_code: impl Into<String>) -> Locale
pub fn language_code(self, language_code: impl Into<String>) -> Locale
Dart Locale.fromSubtags(languageCode:); a deprecated subtag becomes its
preferred value.
Sourcepub fn script_code(self, script_code: impl Into<String>) -> Locale
pub fn script_code(self, script_code: impl Into<String>) -> Locale
Dart Locale.fromSubtags(scriptCode:).
Sourcepub fn country_code(self, country_code: impl Into<String>) -> Locale
pub fn country_code(self, country_code: impl Into<String>) -> Locale
Dart Locale(languageCode, countryCode) / Locale.fromSubtags(countryCode:); a
deprecated subtag becomes its preferred value, and '' is no country at all.
Sourcepub fn to_language_tag(&self) -> String
pub fn to_language_tag(&self) -> String
Returns a syntactically valid Unicode BCP47 Locale Identifier.
Some examples of such identifiers: “en”, “es-419”, “hi-Deva-IN” and “zh-Hans-CN”. See http://www.unicode.org/reports/tr35/ for technical details.
Trait Implementations§
impl Eq for Locale
impl StructuralPartialEq for Locale
Auto Trait Implementations§
impl Freeze for Locale
impl RefUnwindSafe for Locale
impl Send for Locale
impl Sync for Locale
impl Unpin for Locale
impl UnsafeUnpin for Locale
impl UnwindSafe for Locale
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.