Framework for embedding localizations into Rust types
//! Example showing how to localize paths

use camino::Utf8PathBuf;
use icu_locale::locale;
use l10n_embed::{Context, Localize};

fn main() -> Result<(), std::io::Error> {
    // Create some paths
    let current_directory = std::env::current_dir()?;
    let current_directory_utf8 = Utf8PathBuf::from_path_buf(current_directory.clone()).unwrap();

    // Localize these paths, which just prints the path as a string (lossily if using std::path)
    let directories: [(&str, Box<dyn Localize>); 2] = [
        ("Current directory", Box::new(current_directory)),
        (
            "Current directory (UTF-8)",
            Box::new(current_directory_utf8),
        ),
    ];

    let context = Context::new(locale!("en-US"), true);
    let mut buffer = String::new();

    for (name, directory) in directories {
        buffer.clear();
        directory.localize(&context, &mut buffer);

        println!("{name}: {buffer}");
    }

    Ok(())
}