Change lists to be based on type (and, or, unit) rather than length (wide, short, narrow)
Dependencies
- [2]
2HHBS7VWAdd rudimentary support for localizing lists - [3]
Q7LUHXXBReplace localization of `Vec<Localize>` with `List` type - [4]
RA3H7PWCRefactor `Localize` for performance - [5]
GOMTCPOLPass colors through a field in `Context` rather than on `Styled` directly - [6]
PGBXJWIHMove `l10n_embed` re-exports into `macro_prelude` module - [*]
HHJDRLLNCreate `fluent_embed_runtime` crate
Change contents
- 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; - replacement in l10n_embed/src/list.rs at line 11
pub struct List<L: Localize> {messages: Vec<L>,length: ListLength,pub enum ListType {And,Or,Unit, - replacement in l10n_embed/src/list.rs at line 17
impl<L: Localize> List<L> {pub fn new(messages: Vec<L>, length: ListLength) -> Self {Self { messages, length }}}macro_rules! list_impl {($list_name:ident, $list_type:path) => {pub struct $list_name<L: Localize> {messages: Vec<L>,} - replacement in l10n_embed/src/list.rs at line 23
impl<L: Localize> Length for List<L> {fn len(&self) -> usize {self.messages.len()}}impl<L: Localize> $list_name<L> {pub fn new(messages: Vec<L>) -> Self {Self { messages }}} - replacement in l10n_embed/src/list.rs at line 29
impl<L: Localize> Localize for List<L> {fn localize(&self, context: &Context, buffer: &mut String) {let list_formatter = context.list_formatter(self.length);impl<L: Localize> Length for $list_name<L> {fn len(&self) -> usize {self.messages.len()}} - replacement in l10n_embed/src/list.rs at line 35
let localized_messages = self.messages.iter().map(|message| {let mut buffer = String::new();message.localize(context, &mut buffer);impl<L: Localize> Localize for $list_name<L> {fn localize(&self, context: &Context, buffer: &mut String) {let list_formatter = context.list_formatter($list_type); - replacement in l10n_embed/src/list.rs at line 39
buffer});let localized_messages = self.messages.iter().map(|message| {let mut buffer = String::new();message.localize(context, &mut buffer); - replacement in l10n_embed/src/list.rs at line 43
let formatted_list = list_formatter.format(localized_messages);formatted_list.write_to(buffer).unwrap();}buffer});let formatted_list = list_formatter.format(localized_messages);formatted_list.write_to(buffer).unwrap();}}}; - edit in l10n_embed/src/list.rs at line 52[3.1084]
list_impl!(AndList, ListType::And);list_impl!(OrList, ListType::Or);list_impl!(UnitList, ListType::Unit); - replacement in l10n_embed/src/lib.rs at line 16
use icu_list::options::{ListFormatterOptions, ListLength};use icu_list::options::ListFormatterOptions; - replacement in l10n_embed/src/lib.rs at line 72
pub fn list_formatter(&self, length: ListLength) -> &ListFormatter {let index = match length {ListLength::Wide => 0,ListLength::Short => 1,ListLength::Narrow => 2,_ => unimplemented!(),pub fn list_formatter(&self, list_type: list::ListType) -> &ListFormatter {let index = match list_type {list::ListType::And => 0,list::ListType::Or => 1,list::ListType::Unit => 2, - replacement in l10n_embed/src/lib.rs at line 80
ListFormatter::try_new_and(ListFormatterPreferences::from(&self.locale),ListFormatterOptions::default().with_length(length),)let preferences = ListFormatterPreferences::from(&self.locale);let options = ListFormatterOptions::default();match list_type {list::ListType::And => ListFormatter::try_new_and(preferences, options),list::ListType::Or => ListFormatter::try_new_or(preferences, options),list::ListType::Unit => ListFormatter::try_new_unit(preferences, options),} - replacement in l10n_embed/examples/list.rs at line 4
use l10n_embed::list::{List, ListLength};use l10n_embed::list::{AndList, OrList, UnitList}; - replacement in l10n_embed/examples/list.rs at line 11
let 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);let and_list = AndList::new(items.clone());let or_list = OrList::new(items.clone());let unit_list = UnitList::new(items.clone()); - replacement in l10n_embed/examples/list.rs at line 17
("Narrow list", Box::new(narrow_list)),("Short list", Box::new(short_list)),("Wide list", Box::new(wide_list)),("And list", Box::new(and_list)),("Or list", Box::new(or_list)),("Unit list", Box::new(unit_list)),