Struct icu_locid_transform::LocaleFallbacker
source · pub struct LocaleFallbacker {
likely_subtags: DataPayload<LocaleFallbackLikelySubtagsV1Marker>,
parents: DataPayload<LocaleFallbackParentsV1Marker>,
collation_supplement: Option<DataPayload<CollationFallbackSupplementV1Marker>>,
}
Expand description
Implements the algorithm defined in UTS #35: Locale Inheritance and Matching.
Note that this implementation performs some additional steps compared to the UTS #35 algorithm. See the design doc for a detailed description and #2243 to track alignment with UTS #35.
If running fallback in a loop, use DataLocale::is_und()
to break from the loop.
§Examples
use icu::locid::locale;
use icu::locid_transform::fallback::LocaleFallbacker;
// Set up a LocaleFallbacker with data.
let fallbacker = LocaleFallbacker::new();
// Create a LocaleFallbackerIterator with a default configuration.
// By default, uses language priority with no additional extension keywords.
let mut fallback_iterator = fallbacker
.for_config(Default::default())
.fallback_for(locale!("hi-Latn-IN").into());
// Run the algorithm and check the results.
assert_eq!(fallback_iterator.get(), &locale!("hi-Latn-IN").into());
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &locale!("hi-Latn").into());
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &locale!("en-IN").into());
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &locale!("en-001").into());
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &locale!("en").into());
fallback_iterator.step();
assert_eq!(fallback_iterator.get(), &locale!("und").into());
Fields§
§parents: DataPayload<LocaleFallbackParentsV1Marker>
§collation_supplement: Option<DataPayload<CollationFallbackSupplementV1Marker>>
Implementations§
source§impl LocaleFallbacker
impl LocaleFallbacker
sourcepub const fn new<'a>() -> LocaleFallbackerBorrowed<'a>
pub const fn new<'a>() -> LocaleFallbackerBorrowed<'a>
Creates a LocaleFallbacker
with compiled fallback data (likely subtags and parent locales).
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
) -> Result<Self, DataError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), ) -> Result<Self, DataError>
A version of [Self :: new
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
pub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
A version of Self::new
that uses custom data provided by a DataProvider
.
sourcepub fn new_without_data() -> Self
pub fn new_without_data() -> Self
Creates a LocaleFallbacker
without fallback data. Using this constructor may result in
surprising behavior, especially in multi-script languages.
sourcepub fn for_config(
&self,
config: LocaleFallbackConfig,
) -> LocaleFallbackerWithConfig<'_>
pub fn for_config( &self, config: LocaleFallbackConfig, ) -> LocaleFallbackerWithConfig<'_>
Associates a configuration with this fallbacker.
sourcepub fn as_borrowed(&self) -> LocaleFallbackerBorrowed<'_>
pub fn as_borrowed(&self) -> LocaleFallbackerBorrowed<'_>
Creates a borrowed version of this fallbacker for performance.