pub struct Locale { /* private fields */ }Expand description
A language, and optionally the script and the country it is written in
(locale.dart).
The language is required and the other two are not, which is the reference’s shape and
the useful one: fr is an answer, fr-CA is a better one, and zh-Hant-TW needs all
three to be right.
Comparison is exact — fr is not fr-CA. Deciding that one of them will do for the
other is resolve’s work, and it takes the whole list to do it.
Implementations§
Source§impl Locale
impl Locale
Sourcepub fn with_country(
language: impl Into<String>,
country: impl Into<String>,
) -> Locale
pub fn with_country( language: impl Into<String>, country: impl Into<String>, ) -> Locale
A language in a country: Locale::with_country("fr", "CA").
Sourcepub fn script(self, script: impl Into<String>) -> Locale
pub fn script(self, script: impl Into<String>) -> Locale
Adds a script (Hant, Latn): the writing system, which for some languages is
the question that decides legibility rather than idiom.
Sourcepub fn language_code(&self) -> &str
pub fn language_code(&self) -> &str
The language subtag, lowercase. Always present.
Sourcepub fn script_code(&self) -> Option<&str>
pub fn script_code(&self) -> Option<&str>
The script subtag, title case, if there is one.
Sourcepub fn country_code(&self) -> Option<&str>
pub fn country_code(&self) -> Option<&str>
The country subtag, uppercase, if there is one.
Sourcepub fn parse(tag: &str) -> Option<Locale>
pub fn parse(tag: &str) -> Option<Locale>
Reads a language tag: fr, fr-CA, fr_CA, zh-Hant-TW, en-US.UTF-8,
pt_BR@euro.
Both separators, because both arrive: a language tag uses - and a POSIX
environment variable uses _. The encoding and modifier suffixes a Unix LANG
carries are dropped — en_US.UTF-8 is the en-US locale in a particular byte
encoding, and the encoding is not part of which language this is.
A subtag is read by shape, as BCP 47 does: four letters is a script, two
letters or three digits is a region. That is what lets zh-Hant and zh-TW both
be understood without a table of every code.
Returns None for a tag with no language in it at all, including the C and
POSIX locales, which name an absence of one.