Replace localization of `Vec<Localize>` with `List` type
Dependencies
- [2]
7M4UI3TWUpdate dependencies to latest versions - [3]
RUCC2HKZRename from `fluent_embed` to `l10n_embed` - [4]
USKESL6XAdd examples for using common types in `l10n_embed` - [5]
X6AMFX3NTemporarily remove automatic language detection - [6]
2HHBS7VWAdd rudimentary support for localizing lists - [*]
UKFEFT6LCreate basic `Output` proc-macro - [*]
VZYZRAO4Move `output-macros` crate into workspace - [*]
HHJDRLLNCreate `fluent_embed_runtime` crate
Change contents
- edit in Cargo.lock at line 740
"icu_list", - edit in Cargo.toml at line 39
icu_list = "2.0" - edit in l10n_embed/src/list.rs at line 2
/// Re-export from [`icu_locale`] for convenience when constructing a [`List`]pub use icu_list::options::ListLength; - edit in l10n_embed/src/list.rs at line 8
use icu_list::ListFormatter;use icu_list::options::ListFormatterOptions; - replacement in l10n_embed/src/list.rs at line 12
macro_rules! impl_list {($list_type:ty) => {impl<T: Localize> Localize for $list_type {fn localize_for(&self, locale: &Locale) -> String {let localized_items: Vec<String> =self.iter().map(|item| item.localize_for(locale)).collect();localized_items.join("\n")}}};pub trait Length {fn len(&self) -> usize;}pub struct List<L: Localize> {messages: Vec<L>,length: ListLength, - replacement in l10n_embed/src/list.rs at line 21
impl_list!(Vec<T>);impl_list!(&[T]);[6.513]impl<L: Localize> List<L> {pub fn new(messages: Vec<L>, length: ListLength) -> Self {Self { messages, length }}}impl<L: Localize> Length for List<L> {fn len(&self) -> usize {self.messages.len()}}impl<L: Localize> Localize for List<L> {fn localize_for(&self, locale: &Locale) -> String {let list_formatter = ListFormatter::try_new_and(locale.into(),ListFormatterOptions::default().with_length(self.length),).unwrap();let localized_messages = self.messages.iter().map(|message| message.localize_for(locale));list_formatter.format(localized_messages).to_string()}} - edit in l10n_embed/Cargo.toml at line 23
icu_list.workspace = true - file addition: list.rs[4.20]
//! Example showing how to localize listsuse icu_locale::{Locale, locale};use l10n_embed::Localize;use l10n_embed::list::{List, ListLength};const DEFAULT_LOCALE: Locale = locale!("en-US");fn main() {let items = vec!["item 1", "item 2", "item 3", "item 4"];// Create some lists of different lengthslet narrow_list = List::new(items.clone(), ListLength::Narrow);let short_list = List::new(items.clone(), ListLength::Short);let wide_list = List::new(items.clone(), ListLength::Wide);// Localize these listsprintln!("Narrow list: {}", narrow_list.localize_for(&DEFAULT_LOCALE));println!("Short list: {}", short_list.localize_for(&DEFAULT_LOCALE));println!("Wide list: {}", wide_list.localize_for(&DEFAULT_LOCALE));}