//! Example showing how to localize strings
usestd::borrow::Cow;useicu_locale::locale;usel10n_embed::{Context, Localize};fnmain(){// Create some strings
let static_str ="&str";let heap_allocated_string =String::from("String");let copy_on_write_str =Cow::from("Cow<str>");// Localize these strings, which just prints them.
// This would mostly be useful for non-localizable content such as usernames or URLs
let strings:[(&str,Box<dyn Localize>);3]=[("Static string",Box::new(static_str)),("Heap allocated string",Box::new(heap_allocated_string)),("Copy on write string",Box::new(copy_on_write_str)),];let context =Context::new(locale!("en-US"),true);letmut buffer =String::new();for(name, string)in strings {
buffer.clear();
string.localize(&context,&mut buffer);println!("{name}: {buffer}");}}