Debian Codegraph @

third_party/rust/icu_locid_transform/README.md

raw
1 # icu_locid_transform [![crates.io](https://img.shields.io/crates/v/icu_locid_transform)](https://crates.io/crates/icu_locid_transform)
2
3 <!-- cargo-rdme start -->
4
5 Canonicalization of locale identifiers based on [`CLDR`] data.
6
7 This module is published as its own crate ([`icu_locid_transform`](https://docs.rs/icu_locid_transform/latest/icu_locid_transform/))
8 and as part of the [`icu`](https://docs.rs/icu/latest/icu/) crate. See the latter for more details on the ICU4X project.
9
10 It currently supports locale canonicalization based upon the canonicalization
11 algorithm from [`UTS #35: Unicode LDML 3. LocaleId Canonicalization`],
12 as well as the minimize and maximize likely subtags algorithms
13 as described in [`UTS #35: Unicode LDML 3. Likely Subtags`].
14
15 The maximize method potentially updates a passed in locale in place
16 depending up the results of running the 'Add Likely Subtags' algorithm
17 from [`UTS #35: Unicode LDML 3. Likely Subtags`].
18
19 This minimize method returns a new Locale that is the result of running the
20 'Remove Likely Subtags' algorithm from [`UTS #35: Unicode LDML 3. Likely Subtags`].
21
22 ## Examples
23
24 ```rust
25 use icu::locid::Locale;
26 use icu::locid_transform::{LocaleCanonicalizer, TransformResult};
27
28 let lc = LocaleCanonicalizer::new();
29
30 let mut locale: Locale = "ja-Latn-fonipa-hepburn-heploc"
31 .parse()
32 .expect("parse failed");
33 assert_eq!(lc.canonicalize(&mut locale), TransformResult::Modified);
34 assert_eq!(locale, "ja-Latn-alalc97-fonipa".parse::<Locale>().unwrap());
35 ```
36
37 ```rust
38 use icu::locid::locale;
39 use icu::locid_transform::{LocaleExpander, TransformResult};
40
41 let lc = LocaleExpander::new();
42
43 let mut locale = locale!("zh-CN");
44 assert_eq!(lc.maximize(&mut locale), TransformResult::Modified);
45 assert_eq!(locale, locale!("zh-Hans-CN"));
46
47 let mut locale = locale!("zh-Hant-TW");
48 assert_eq!(lc.maximize(&mut locale), TransformResult::Unmodified);
49 assert_eq!(locale, locale!("zh-Hant-TW"));
50 ```
51
52 ```rust
53 use icu::locid::locale;
54 use icu::locid_transform::{LocaleExpander, TransformResult};
55 use writeable::assert_writeable_eq;
56
57 let lc = LocaleExpander::new();
58
59 let mut locale = locale!("zh-Hans-CN");
60 assert_eq!(lc.minimize(&mut locale), TransformResult::Modified);
61 assert_eq!(locale, locale!("zh"));
62
63 let mut locale = locale!("zh");
64 assert_eq!(lc.minimize(&mut locale), TransformResult::Unmodified);
65 assert_eq!(locale, locale!("zh"));
66 ```
67
68 [`ICU4X`]: ../icu/index.html
69 [`CLDR`]: http://cldr.unicode.org/
70 [`UTS #35: Unicode LDML 3. Likely Subtags`]: https://www.unicode.org/reports/tr35/#Likely_Subtags.
71 [`UTS #35: Unicode LDML 3. LocaleId Canonicalization`]: http://unicode.org/reports/tr35/#LocaleId_Canonicalization,
72
73 <!-- cargo-rdme end -->
74
75 ## More Information
76
77 For more information on development, authorship, contributing etc. please visit [`ICU4X home page`](https://github.com/unicode-org/icu4x).