1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
//! Options for [`DisplayNames`](crate::DisplayNames).
/// A bag of options defining how region or language codes will be translated.
///
/// # Example
///
/// ```
/// use icu::experimental::displaynames::{
/// DisplayNamesOptions, RegionDisplayNames, Style,
/// };
/// use icu::locale::{locale, subtags::region};
///
/// let locale = locale!("en-001");
/// let mut options: DisplayNamesOptions = Default::default();
/// options.style = Some(Style::Short);
/// let display_name = RegionDisplayNames::try_new(&locale.into(), options)
/// .expect("Data should load successfully");
///
/// // Full name would be "Bosnia & Herzegovina"
/// assert_eq!(display_name.of(region!("BA")), Some("Bosnia"));
/// ```
#[derive(Copy, Debug, Eq, PartialEq, Clone, Default)]
#[non_exhaustive]
pub struct DisplayNamesOptions {
/// The optional formatting style to use for display name.
pub style: Option<Style>,
/// The fallback return when the system does not have the
/// requested display name, defaults to "code".
pub fallback: Fallback,
/// The language display kind, defaults to "dialect".
pub language_display: LanguageDisplay,
}
/// An enum for formatting style.
#[allow(missing_docs)] // The variants are self explanatory.
#[non_exhaustive]
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub enum Style {
Narrow,
Short,
Long,
Menu,
}
/// An enum for fallback return when the system does not have the
/// requested display name.
#[allow(missing_docs)] // The variants are self explanatory.
#[non_exhaustive]
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub enum Fallback {
Code,
None,
}
impl Default for Fallback {
fn default() -> Self {
Self::Code
}
}
/// An enum for the language display kind.
#[allow(missing_docs)] // The variants are self explanatory.
#[non_exhaustive]
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub enum LanguageDisplay {
Dialect,
Standard,
}
impl Default for LanguageDisplay {
fn default() -> Self {
Self::Dialect
}
}