[][src]Struct rocket_accept_language::Locale

pub struct Locale { /* fields omitted */ }

A Locale object.

Locale object stores information encoded in a language tag and provides methods allowing for parsing, serializing and manipulating locale fields.

All data is validated and canonicalized on input, which means that the output is always canonicalized.

Currently supported subtags are:

  • language (e.g. "en")
  • script (e.g. "Latn")
  • region (e.g. "US")
  • variants (e.g. "windows")
  • extensions (e.g. "-u-ca-gregorian-hc-h12")

The API parses correctly the remaining fields of the BCP47 language tag, but at the moment does not provide any API for operating on them.

Examples

Parsing

Locale supports a From trait from String and &str:

use fluent_locale::Locale;

let loc = Locale::from("en-latn-us");

assert_eq!(loc.to_string(), "en-Latn-US");

Locale can also accept options, similarly to ECMA402 Intl.Locale:

use fluent_locale::Locale;
use std::collections::BTreeMap;

let mut opts = BTreeMap::new();
opts.insert("hour-cycle", "h12");
let loc = Locale::new("en", Some(opts)).unwrap();

assert_eq!(loc.to_string(), "en-u-hc-h12");

Serializing

Locale supports Display trait allowing for:

use fluent_locale::Locale;
use std::collections::BTreeMap;

let mut opts = BTreeMap::new();
opts.insert("hour-cycle", "h12");
let loc = Locale::new("en-Latn-US-u-hc-h23", Some(opts)).unwrap();

assert_eq!(loc.to_string(), "en-Latn-US-u-hc-h12");

Manipulating

During the lifetime of Locale, its fields can be modified via getter/setter methods:

use fluent_locale::Locale;

let mut loc = Locale::from("en-Latn-US");
loc.set_region("GB").unwrap();

assert_eq!(loc.to_string(), "en-Latn-GB");

Methods

impl Locale[src]

pub fn new(
    loc_str: &str,
    opts: Option<BTreeMap<&str, &str>>
) -> Result<Locale, Error>
[src]

pub fn set_language(&mut self, value: &str) -> Result<(), Error>[src]

pub fn get_language(&self) -> &str[src]

pub fn set_script(&mut self, value: &str) -> Result<(), Error>[src]

pub fn get_script(&self) -> &str[src]

pub fn set_region(&mut self, value: &str) -> Result<(), Error>[src]

pub fn get_region(&self) -> &str[src]

pub fn add_variant(&mut self, value: String)[src]

pub fn remove_variant(&mut self, value: String)[src]

pub fn get_variants(&self) -> Vec<&String>[src]

pub fn clear_variants(&mut self)[src]

pub fn has_privateuse(&self) -> bool[src]

pub fn get_extensions(&self) -> BTreeMap<String, &BTreeMap<String, String>>[src]

pub fn add_extension(&mut self, ext_name: String, key: String, value: String)[src]

pub fn matches(
    &self,
    other: &Locale,
    available_range: bool,
    requested_range: bool
) -> bool
[src]

Trait Implementations

impl Default for Locale[src]

impl Clone for Locale[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Locale[src]

impl Display for Locale[src]

impl PartialEq<Locale> for Locale[src]

impl<'a> From<&'a str> for Locale[src]

impl From<String> for Locale[src]

Auto Trait Implementations

impl Send for Locale

impl Sync for Locale

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Typeable for T where
    T: Any

fn get_type(&self) -> TypeId

Get the TypeId of this object.

impl<T> IntoCollection<T> for T

impl<T, I> AsResult<T, I> for T where
    I: Input,