Struct locale_config::Locale
[−]
[src]
pub struct Locale { /* fields omitted */ }
Locale configuration.
Users may accept several languages in some order of preference and may want to use rules from different culture for some particular aspect of the program behaviour, and operating systems allow them to specify this (to various extent).
The Locale
objects represent the user configuration. They contain:
- The primary
LanguageRange
. - Optional category-specific overrides.
- Optional fallbacks in case data (usually translations) for the primary language are not available.
The set of categories is open-ended. The locale
crate uses five well-known categories
messages
, numeric
, time
, collate
and monetary
, but some systems define additional
ones (GNU Linux has additionally paper
, name
, address
, telephone
and measurement
) and
these are provided in the user default Locale
and other libraries can use them.
Locale
is represented by a ,
-separated sequence of tags in LanguageRange
syntax, where
all except the first one may be preceded by category name and =
sign.
The first tag indicates the default locale, the tags prefixed by category names indicate overrides for those categories and the remaining tags indicate fallbacks.
Note that a syntactically valid value of HTTP Accept-Language
header is a valid Locale
. Not
the other way around though due to the presence of category selectors.
Methods
impl Locale
[src]
fn user_default() -> Locale
Obtain the user default locale.
This is the locale indicated by operating environment.
fn global_default() -> Locale
Obtain the global default locale.
The global default for current()
locale. Defaults to user_default()
.
fn set_global_default(lb: Locale)
Change the global default locale.
Setting this overrides the default for new threads and threads that didn't do any locale-aware operation yet.
fn current() -> Locale
Obtain the current locale of current thread.
Defaults to global_default()
on first use in each thread.
fn set_current(lb: Locale)
Change the current locale of current thread.
fn new(s: &str) -> Result<Locale, Error>
Construct locale from the string representation.
Locale
is represented by a ,
-separated sequence of tags in LanguageRange
syntax, where
all except the first one may be preceded by category name and =
sign.
The first tag indicates the default locale, the tags prefixed by category names indicate overrides for those categories and the remaining tags indicate fallbacks.
fn invariant() -> Locale
Construct invariant locale.
Invariant locale is represented simply with empty string.
fn add(&mut self, tag: &LanguageRange)
Append fallback language tag.
Adds fallback to the end of the list.
fn add_category(&mut self, category: &str, tag: &LanguageRange)
Append category override.
Appending new override for a category that already has one will not replace the existing override. This might change in future.
Iterate over LanguageRange
s in this Locale
.
Returns tuples of optional category (as string) and corresponding LanguageRange
. All tags
in the list are returned, in order of preference.
The iterator is guaranteed to return at least one value.
Iterate over LanguageRange
s in this Locale
applicable to given category.
Returns LanguageRange
s in the Locale
that are applicable to provided category. The tags
are returned in order of preference, which means the category-specific ones first and then
the generic ones.
The iterator is guaranteed to return at least one value.
Trait Implementations
impl Clone for Locale
[src]
fn clone(&self) -> Locale
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for Locale
[src]
impl Eq for Locale
[src]
impl Hash for Locale
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.
impl PartialEq for Locale
[src]
fn eq(&self, __arg_0: &Locale) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Locale) -> bool
This method tests for !=
.
impl AsRef<str> for Locale
[src]
Locale is specified by a string tag. This is the way to access it.
impl<'a> From<LanguageRange<'a>> for Locale
[src]
fn from(t: LanguageRange<'a>) -> Locale
Performs the conversion.