Expand description

Tools for locale fallback, enabling arbitrary input locales to be mapped into the nearest locale with data.

The algorithm implemented in this module is called Flexible Vertical Fallback. Watch #2243 to track improvements to this algorithm and steps to enshrine the algorithm in CLDR.

Examples

Run the locale fallback algorithm:

use icu_provider_adapters::fallback::LocaleFallbacker;
use icu_provider::prelude::*;

// Set up a LocaleFallbacker with data.
let fallbacker = LocaleFallbacker::try_new_unstable(&icu_testdata::unstable()).expect("data");

// Create a LocaleFallbackerWithConfig with a configuration for a specific key.
// By default, uses language priority with no additional extension keywords.
let key_fallbacker = fallbacker.for_config(Default::default());

// Set up the fallback iterator.
let mut fallback_iterator = key_fallbacker.fallback_for(icu_locid::locale!("hi-Latn-IN").into());

// Run the algorithm and check the results.
assert_eq!(fallback_iterator.get().to_string(), "hi-Latn-IN");
fallback_iterator.step();
assert_eq!(fallback_iterator.get().to_string(), "hi-Latn");
fallback_iterator.step();
assert_eq!(fallback_iterator.get().to_string(), "en-IN");
fallback_iterator.step();
assert_eq!(fallback_iterator.get().to_string(), "en-001");
fallback_iterator.step();
assert_eq!(fallback_iterator.get().to_string(), "en");
fallback_iterator.step();
assert_eq!(fallback_iterator.get().to_string(), "und");

Modules

Data provider struct definitions for vertical fallback.

Structs

Configuration settings for a particular fallback operation.
Iteration type for locale fallback operations.
A data provider wrapper that performs locale fallback. This enables arbitrary locales to be handled at runtime.
Entry type for locale fallbacking.
Intermediate type for spawning locale fallback iterators based on a specific configuration.