rust_intl 0.2.0

A Rust internationalization library
Documentation
//! Runtime interpreter for the `'static` AST nodes generated by `load!()`.
//! Uses ICU4X for plurals resolution and number formatting.

mod current;
mod number;
mod plural;
mod render;

pub use current::{get_current_locale, set_current_locale};
pub use number::{Number, NumberArg};
pub use plural::Category;
pub use render::render;

pub(crate) fn parse_icu_locale(code: &str) -> icu_locale_core::Locale {
    code.parse()
        .unwrap_or_else(|_| icu_locale_core::langid!("en").into())
}

/// A node of the pre-parsed message AST.
#[derive(Clone, Copy, Debug)]
pub enum Node {
    Text(&'static str),
    Var(&'static str),
    Plural {
        var: &'static str,
        ordinal: bool,
        arms: &'static [(plural::PluralArm, &'static [Node])],
    },
    Select {
        var: &'static str,
        arms: &'static [(&'static str, &'static [Node])],
    },
}

pub use plural::PluralArm;

/// A resolved translation argument, as passed to [`render`].
pub enum Value<'a> {
    String(&'a str),
    Number(&'a NumberArg),
}