Framework for embedding localizations into Rust types
//! Example showing how to style localized types

use anstyle::AnsiColor;
use icu_locale::{Locale, locale};
use jiff::Timestamp;
use l10n_embed::Localize;
use l10n_embed::style::Styled;

const DEFAULT_LOCALE: Locale = locale!("en-US");
// This is used to disable rendering of colors, e.g. based on user configuration
const STYLE_ENABLED: bool = true;

fn main() {
    // Create some localizable data to be styled
    let five_million: Styled<u64> = Styled::new(5_000_000, STYLE_ENABLED)
        .bold()
        .color(AnsiColor::Green);
    let static_str: Styled<&'static str> = Styled::new("&str", STYLE_ENABLED)
        .italic()
        .color(AnsiColor::Blue);
    let unix_epoch: Styled<Timestamp> = Styled::new(Timestamp::UNIX_EPOCH, STYLE_ENABLED)
        .strikethrough()
        .color(AnsiColor::Red);

    // Localize these strings, which adds colors (if enabled) and forwards to the stored type's implementation.
    println!(
        "Five million: {}",
        five_million.localize_for(&DEFAULT_LOCALE)
    );
    println!(
        "Static string: {}",
        static_str.localize_for(&DEFAULT_LOCALE)
    );
    println!("Unix epoch: {}", unix_epoch.localize_for(&DEFAULT_LOCALE));
}