Struct icu::displaynames::LocaleDisplayNamesFormatter
source · pub struct LocaleDisplayNamesFormatter { /* private fields */ }
Expand description
Format a locale as a display string.
Example
use icu_displaynames::{DisplayNamesOptions, LocaleDisplayNamesFormatter};
use icu_locid::{locale, subtags_language as language};
let locale = locale!("en-001");
let options: DisplayNamesOptions = Default::default();
let display_name = LocaleDisplayNamesFormatter::try_new_unstable(
&icu_testdata::unstable(),
&locale.into(),
options,
)
.expect("Data should load successfully");
assert_eq!(display_name.of(&locale!("de-CH")), "Swiss High German");
assert_eq!(display_name.of(&locale!("de")), "German");
assert_eq!(display_name.of(&locale!("de-MX")), "German (Mexico)");
assert_eq!(display_name.of(&locale!("xx-YY")), "xx (YY)");
assert_eq!(display_name.of(&locale!("xx")), "xx");
Implementations§
source§impl LocaleDisplayNamesFormatter
impl LocaleDisplayNamesFormatter
sourcepub fn try_new_unstable<D>(
data_provider: &D,
locale: &DataLocale,
options: DisplayNamesOptions
) -> Result<LocaleDisplayNamesFormatter, DataError>where
D: DataProvider<LocaleDisplayNamesV1Marker> + DataProvider<LanguageDisplayNamesV1Marker> + DataProvider<ScriptDisplayNamesV1Marker> + DataProvider<RegionDisplayNamesV1Marker> + ?Sized,
pub fn try_new_unstable<D>( data_provider: &D, locale: &DataLocale, options: DisplayNamesOptions ) -> Result<LocaleDisplayNamesFormatter, DataError>where D: DataProvider<LocaleDisplayNamesV1Marker> + DataProvider<LanguageDisplayNamesV1Marker> + DataProvider<ScriptDisplayNamesV1Marker> + DataProvider<RegionDisplayNamesV1Marker> + ?Sized,
Creates a new LocaleDisplayNamesFormatter
from locale data and an options bag.
⚠️ The bounds on this function may change over time, including in SemVer minor releases.
sourcepub fn try_new_with_any_provider(
provider: &impl AnyProvider,
locale: &DataLocale,
options: DisplayNamesOptions
) -> Result<LocaleDisplayNamesFormatter, DataError>
pub fn try_new_with_any_provider( provider: &impl AnyProvider, locale: &DataLocale, options: DisplayNamesOptions ) -> Result<LocaleDisplayNamesFormatter, DataError>
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,
locale: &DataLocale,
options: DisplayNamesOptions
) -> Result<LocaleDisplayNamesFormatter, DataError>
pub fn try_new_with_buffer_provider( provider: &impl BufferProvider, locale: &DataLocale, options: DisplayNamesOptions ) -> Result<LocaleDisplayNamesFormatter, DataError>
✨ 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