Struct icu_locid_transform::LocaleCanonicalizer
source · 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§
source§impl LocaleCanonicalizer
impl LocaleCanonicalizer
sourcepub fn try_new_unstable<P>(
provider: &P
) -> Result<LocaleCanonicalizer, LocaleTransformError>where
P: DataProvider<AliasesV1Marker> + DataProvider<LikelySubtagsForLanguageV1Marker> + DataProvider<LikelySubtagsForScriptRegionV1Marker> + ?Sized,
pub fn try_new_unstable<P>( provider: &P ) -> Result<LocaleCanonicalizer, LocaleTransformError>where P: DataProvider<AliasesV1Marker> + DataProvider<LikelySubtagsForLanguageV1Marker> + DataProvider<LikelySubtagsForScriptRegionV1Marker> + ?Sized,
A constructor which takes a DataProvider
and creates a LocaleCanonicalizer
.
sourcepub fn try_new_with_any_provider(
provider: &impl AnyProvider + ?Sized
) -> Result<LocaleCanonicalizer, LocaleTransformError>
pub fn try_new_with_any_provider( provider: &impl AnyProvider + ?Sized ) -> Result<LocaleCanonicalizer, LocaleTransformError>
Creates a new instance using an AnyProvider
.
For details on the behavior of this function, see: Self::try_new_unstable
sourcepub fn try_new_with_buffer_provider(
provider: &impl BufferProvider + ?Sized
) -> Result<LocaleCanonicalizer, LocaleTransformError>
pub fn try_new_with_buffer_provider( provider: &impl BufferProvider + ?Sized ) -> Result<LocaleCanonicalizer, LocaleTransformError>
✨ 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
sourcepub fn try_new_with_expander_unstable<P>(
provider: &P,
expander: LocaleExpander
) -> Result<LocaleCanonicalizer, LocaleTransformError>where
P: DataProvider<AliasesV1Marker> + ?Sized,
pub fn try_new_with_expander_unstable<P>( provider: &P, expander: LocaleExpander ) -> Result<LocaleCanonicalizer, LocaleTransformError>where P: DataProvider<AliasesV1Marker> + ?Sized,
Creates a LocaleCanonicalizer
with a custom LocaleExpander
object.
For example, use this constructor if you wish to support all languages.
sourcepub fn canonicalize(&self, locale: &mut Locale) -> TransformResult
pub fn canonicalize(&self, locale: &mut Locale) -> TransformResult
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());