|
14 | 14 | //! |
15 | 15 | //! ``` |
16 | 16 | //! use icu_locid::locale; |
17 | | -//! use icu_locid_transform::fallback::LocaleFallbacker; |
| 17 | +//! use icu_locid_transform::LocaleFallbacker; |
18 | 18 | //! |
19 | 19 | //! // Set up a LocaleFallbacker with data. |
20 | 20 | //! let fallbacker = LocaleFallbacker::new(); |
@@ -49,9 +49,44 @@ pub use icu_provider::fallback::*; |
49 | 49 |
|
50 | 50 | mod algorithms; |
51 | 51 |
|
52 | | -/// Entry type for locale fallbacking. |
| 52 | +/// Implements the algorithm defined in *[UTS #35: Locale Inheritance and Matching]*. |
53 | 53 | /// |
54 | | -/// See the module-level documentation for an example. |
| 54 | +/// Note that this implementation performs some additional steps compared to the *UTS #35* |
| 55 | +/// algorithm, see *[the design doc]* for a detailed description, and [#2243]( |
| 56 | +/// https://github.com/unicode-org/icu4x/issues/2243) to track aligment with *UTS #35*. |
| 57 | +/// |
| 58 | +/// # Examples |
| 59 | +/// |
| 60 | +/// ``` |
| 61 | +/// use icu_locid::locale; |
| 62 | +/// use icu_locid_transform::fallback::LocaleFallbacker; |
| 63 | +/// |
| 64 | +/// // Set up a LocaleFallbacker with data. |
| 65 | +/// let fallbacker = LocaleFallbacker::new(); |
| 66 | +/// |
| 67 | +/// // Create a LocaleFallbackerIterator with a default configuration. |
| 68 | +/// // By default, uses language priority with no additional extension keywords. |
| 69 | +/// let mut fallback_iterator = fallbacker |
| 70 | +/// .for_config(Default::default()) |
| 71 | +/// .fallback_for(locale!("hi-Latn-IN").into()); |
| 72 | +/// |
| 73 | +/// // Run the algorithm and check the results. |
| 74 | +/// assert_eq!(fallback_iterator.get(), &locale!("hi-Latn-IN").into()); |
| 75 | +/// fallback_iterator.step(); |
| 76 | +/// assert_eq!(fallback_iterator.get(), &locale!("hi-Latn").into()); |
| 77 | +/// fallback_iterator.step(); |
| 78 | +/// assert_eq!(fallback_iterator.get(), &locale!("en-IN").into()); |
| 79 | +/// fallback_iterator.step(); |
| 80 | +/// assert_eq!(fallback_iterator.get(), &locale!("en-001").into()); |
| 81 | +/// fallback_iterator.step(); |
| 82 | +/// assert_eq!(fallback_iterator.get(), &locale!("en").into()); |
| 83 | +/// fallback_iterator.step(); |
| 84 | +/// assert_eq!(fallback_iterator.get(), &locale!("und").into()); |
| 85 | +/// ``` |
| 86 | +/// |
| 87 | +/// [UTS #35: Locale Inheritance and Matching]: https://www.unicode.org/reports/tr35/#Locale_Inheritance |
| 88 | +/// [the design doc]: https://docs.google.com/document/d/1Mp7EUyl-sFh_HZYgyeVwj88vJGpCBIWxzlCwGgLCDwM/edit |
| 89 | +#[doc(hidden)] |
55 | 90 | #[derive(Debug, Clone, PartialEq)] |
56 | 91 | pub struct LocaleFallbacker { |
57 | 92 | likely_subtags: DataPayload<LocaleFallbackLikelySubtagsV1Marker>, |
|
0 commit comments