Crate rust_icu_umsg[][src]

Expand description

Locale-aware message formatting.

Implementation of the text formatting code from the ICU4C umsg.h header. Skip to the section “Example use” below if you want to see it in action.

The library inherits all pattern and formatting specifics from the corresponding ICU C++ API.

This is the support for MessageFormat message formatting. The MessageFormat uses ICU data to format text properly based on the locale selected at formatter initialization. This includes formatting dates, times, currencies, and other text.

Note: The MessageFormat library does not handle loading the format patterns in the appropriate language. This task is left to the application author.

Example use

The example below shows how to format values into an English text. For more detail about formatting specifics see message_format!.

use rust_icu_sys as sys;
use rust_icu_common as common;
use rust_icu_ustring as ustring;
use rust_icu_uloc as uloc;
use rust_icu_umsg::{self as umsg, message_format};

fn testfn() -> Result<(), common::Error> {
    let loc = uloc::ULoc::try_from("en-US-u-tz-uslax")?;
    let msg = ustring::UChar::try_from(
      r"Formatted double: {0,number,##.#},
        Formatted integer: {1,number,integer},
        Formatted string: {2},
        Date: {3,date,full}",

    let fmt = umsg::UMessageFormat::try_from(&msg, &loc)?;
    let hello = ustring::UChar::try_from("Hello! Добар дан!")?;
    let result = umsg::message_format!(
      { 43.4 => Double },
      { 31337 => Integer },
      { hello => String },
      { 0.0 => Date },

      r"Formatted double: 43.4,
        Formatted integer: 31,337,
        Formatted string: Hello! Добар дан!,
        Date: Thursday, January 1, 1970",



Given a formatter, formats the passed arguments into the formatter’s message.



The implementation of the ICU UMessageFormat*.