Remove unnecessary parameters in generated `localize()` function
Dependencies
- [2]
4MRF5E76Generate simple locale matching code in `localize()` - [3]
2XQ6ZB4WStore multiple locales in a single `Group` - [4]
XEEXWJLGAdd simple end-to-end test for selectors - [5]
5FIVUZYFUnify `fluent_embed` macro API as `localize()` - [6]
3WEPY3OXAdd `locale` parameter to derived `localize()` function - [7]
HJMYJDC7Simplify `fluent_embed::group` module - [8]
XGNME3WRMove `Group::derive_enum` to new `crate::parse_macro` module - [9]
VNSHGQYNSupport using glob paths in `localize` macro - [10]
EFVTSBSVAdjust wording of $unreadEmails when there is 1 unread email - [*]
5TEX4MNUSplit `fluent_embed` into `group` and `parse` modules - [*]
BQ6N55O7Refactor how `Group` stores messages - [*]
SHNZZSZGCreate `cli_macros` shim crate
Change contents
- replacement in fluent_embed/src/parse_macro.rs at line 16
let mut extra_messages = Vec::with_capacity(variants.len());let mut canonical_messages = Vec::with_capacity(variants.len());let mut messages = Vec::with_capacity(variants.len()); - replacement in fluent_embed/src/parse_macro.rs at line 37
extra_messages.push(group.message(&kebab_case_ident));canonical_messages.push(group.canonical_message(&kebab_case_ident));messages.push(group.message(&kebab_case_ident)); - replacement in fluent_embed/src/parse_macro.rs at line 40
// TODO: locale matching should use a better algorithmlet extra_locales = group.extra_locales().map(|locale| locale.id.to_string());let canonical_locale = group.canonical_locale().id.to_string(); - replacement in fluent_embed/src/parse_macro.rs at line 45
fn localize(&self, locales: &[&::icu_locid::Locale], plural_rules: &::icu_plurals::PluralRules) -> String {// Check each locale to see if it's implemented for this messagefor locale in locales {match self {#(Self::#idents => #extra_messages),*}}fn localize(&self) -> String {// Find the appropriate locale to uselet extra_locales = [#(::icu_locid::langid!(#extra_locales)),*];let canonical_locale = ::icu_locid::langid!(#canonical_locale);let locale = ::locale_select::match_locales(&extra_locales, &canonical_locale);// TODO: this shouldn't be generated on every call// TODO: handle different rule types according to fluent code (not just cardinal)let plural_rule_type = ::icu_plurals::PluralRuleType::Cardinal;let plural_rules = ::icu_plurals::PluralRules::try_new(&locale.clone().into(), plural_rule_type).unwrap(); - replacement in fluent_embed/src/parse_macro.rs at line 56
// Fall back to default locale// Match the information to the message - replacement in fluent_embed/src/parse_macro.rs at line 58
#(Self::#idents => #canonical_messages),*#(Self::#idents => #messages),* - edit in fluent_embed/src/group.rs at line 98
let canonical_message = crate::parse_fluent::message(&self.canonical_messages[message_column]); - edit in fluent_embed/src/group.rs at line 103
else {#canonical_message} - replacement in fluent_embed/src/group.rs at line 110
pub fn canonical_message(&self, id: &str) -> syn::Expr {let message_column = self.canonical_messages.iter().position(|message| message.id.name == id).expect("Message id must be valid");crate::parse_fluent::message(&self.canonical_messages[message_column])pub fn canonical_locale(&self) -> &Locale {&self.canonical_locale}pub fn extra_locales(&self) -> impl Iterator<Item = &Locale> {self.extra_locales.iter().map(| LocaleGroup { locale, .. }| locale) - edit in cli_macros/tests/selectors.rs at line 4
use icu_locid::locale;use icu_plurals::{PluralRuleType, PluralRules}; - edit in cli_macros/tests/selectors.rs at line 12[3.459]→[3.1292:1327](∅→∅),[3.1327]→[3.459:482](∅→∅),[3.459]→[3.459:482](∅→∅),[3.482]→[3.1328:1417](∅→∅),[3.1417]→[3.570:571](∅→∅),[3.570]→[3.570:571](∅→∅)
let locale = locale!("en-US");let plural_rules =PluralRules::try_new(&locale.clone().into(), PluralRuleType::Cardinal).unwrap(); - replacement in cli_macros/tests/selectors.rs at line 25
message.localize(&[&locale], &plural_rules),message.localize(), - edit in cli_macros/Cargo.toml at line 20[14.1033]
locale_select = { path = "../locale_select" }