pub struct LocaleCanonicalizer { /* private fields */ }
Expand description

The LocaleCanonicalizer provides methods to canonicalize Locales and LanguageIdentifiers based upon CLDR data.

It currently supports locale canonicalization based upon the canonicalization algorithm from UTS #35: Unicode LDML 3. LocaleId Canonicalization.

Examples

use icu_locid::Locale;
use icu_locid_transform::{LocaleCanonicalizer, TransformResult};

let lc = LocaleCanonicalizer::try_new_unstable(&icu_testdata::unstable())
    .expect("create failed");

let mut locale: Locale = "ja-Latn-fonipa-hepburn-heploc".parse().unwrap();
assert_eq!(lc.canonicalize(&mut locale), TransformResult::Modified);
assert_eq!(locale, "ja-Latn-alalc97-fonipa".parse().unwrap());

Implementations

A constructor which takes a DataProvider and creates a LocaleCanonicalizer.

📚 Help choosing a constructor

⚠️ The bounds on this function may change over time, including in SemVer minor releases.

Creates a new instance using an AnyProvider.

For details on the behavior of this function, see: Self::try_new_unstable

📚 Help choosing a constructor

Enabled with the "serde" feature.

Creates a new instance using a BufferProvider.

For details on the behavior of this function, see: Self::try_new_unstable

📚 Help choosing a constructor

The canonicalize method potentially updates a passed in locale in place depending up the results of running the canonicalization algorithm from http://unicode.org/reports/tr35/#LocaleId_Canonicalization.

Some BCP47 canonicalization data is not part of the CLDR json package. Because of this, some canonicalizations are not performed, e.g. the canonicalization of und-u-ca-islamicc to und-u-ca-islamic-civil. This will be fixed in a future release once the missing data has been added to the CLDR json data.

Examples
use icu_locid::Locale;
use icu_locid_transform::{LocaleCanonicalizer, TransformResult};

let lc = LocaleCanonicalizer::try_new_unstable(&icu_testdata::unstable())
    .expect("create failed");

let mut locale: Locale = "ja-Latn-fonipa-hepburn-heploc".parse().unwrap();
assert_eq!(lc.canonicalize(&mut locale), TransformResult::Modified);
assert_eq!(locale, "ja-Latn-alalc97-fonipa".parse().unwrap());

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.