A small consequence is that fluent_embed::time::RelativeTime no longer implements Localize, which may need to be revisited later. Also, now that the caller can override the locale, a valid locale is not guaranteed; might need to add error handling or something similar.'
7U2DXFMPZO4P53AMWYCVXG3EPB7UIAPEY4PDDINX4TTABHD5NGMQC KZLFC7OWYNK3G5YNHRANUK3VUVCM6W6J34N7UABYA24XMZWAVVHQC HHJDRLLNN36UNIA7STAXEEVBCEMPJNB7SJQOS3TJLLYN4AEZ4MHQC NO3PDO7PY7J3WPADNCS5VD6HKFY63E23I3SDR4DHXNVQJTG27RAAC O77KA6C4UJGZXVGPEA7WCRQH6XYQJPWETSPDXI3VOKOSRQND7JEQC F5LG7WENUUDRSCTDMA4M6BAC5RWTGQO45C4ZEBZDX6FHCTTHBVGQC QFPQZR4K4UZ7R2GQZJG4NYBGVQJVL2ANIKGGTOHAMIRIBQHPSQGAC 3WEPY3OXJJ72TNVZLFCN2ZDWSADLT52T6DUONFGEAB46UWAQD3PQC 5TEX4MNUC4LDDRMNEOVCFNUUEZAGUXMKO3OIEQFXWRQKXSHY2NRQC XGNME3WRU3MJDTFHUFJYARLVXWBZIH5ODBOIIFTXHNCBTZQH2R7QC P6FW2GGOW24UZZAWQ6IDDI66JBWTIY26TATMCIOETZ4GRRGGUI3AC 4MRF5E76QSW3EPICI6TNEGJ2KSBWODWMIDQPLYALDWBYWKAV5LJAC QSK7JRBA55ZRY322WXGNRROJL7NTFBR6MJPOOA5B2XD2JAVM4MWQC VNSHGQYNPGKGGPYNVP4Z2RWD7JCSDJVYAADD6UXWBYL6ZRXKLE4AC BFL2Y7GN6NBXXNAUSD4M6T6CIVQ2OLERPE2CAFSLRF377WFFTVCQC // Create a list of available locales to choose fromlet available_locales = [// The canonical locale will always be availableSelf::CANONICAL_LOCALE,// Any additional locales that contain this message#(::fluent_embed::langid!(#additional_locales)),*];let locale = ::fluent_embed::select_locale(&available_locales, &Self::CANONICAL_LOCALE);
pub fn for_struct(
pub fn locales_for_ident(group: &fluent::Group, ident: &syn::Ident) -> TokenStream {let id = ident.to_string().to_kebab_case();let locale_literals = group.locales_for_message(&id).map(|locale| locale.id.to_string()).map(|locale_string| syn::LitStr::new(&locale_string, proc_macro2::Span::call_site()));// There is only one message for this struct, so just list every supported localequote!(vec![#(::fluent_embed::langid!(#locale_literals)),*])}pub fn message_for_struct(
pub fn for_enum(
pub fn locales_for_enum(group: &fluent::Group,enum_variants: &Punctuated<syn::Variant, syn::token::Comma>,) -> TokenStream {let mut match_arms: Vec<TokenStream> = Vec::with_capacity(enum_variants.len());for enum_variant in enum_variants {let variant_ident = &enum_variant.ident;// Simplify match code by always ignoring enum fields (even if they don't exist)// We are matching the variant name, not any data, so each arm will have something like:// Self::VariantName { .. }// Even if `Self::VariantName` doesn't contain any datalet locales_for_variant = locales_for_ident(group, variant_ident);match_arms.push(quote!(Self::#variant_ident { .. } => #locales_for_variant));}quote! {match self {#(#match_arms),*}}}pub fn messages_for_enum(
/// Select which locale to use, falling back to the canonical locale if nothing matchespub fn select_locale(available_locales: &[LanguageIdentifier],canonical_locale: &LanguageIdentifier,) -> LanguageIdentifier {locale_select::match_locales(available_locales, canonical_locale)
fn message_for_locale(&self, locale: &LanguageIdentifier) -> String;fn localize(&self) -> String;