Allows callers to choose the locale at runtime, which is necessary to handle arbitrary configuration. There is no locale fallback implemented yet, so any locale that does not directly match the options implemented will be handled by the default locale (hardcoded to en-US for now).
3WEPY3OXJJ72TNVZLFCN2ZDWSADLT52T6DUONFGEAB46UWAQD3PQC
fn to_syn(&self, canonical_locale: String) -> syn::ExprBlock {
let additional_locales = self
.additional_messages
.keys()
.map(|locale| locale.to_string())
.map(|locale_string| syn::LitStr::new(&locale_string, proc_macro2::Span::call_site()));
let additional_messages = self
.additional_messages
.values()
.map(crate::parse_fluent::message);
let canonical_locale = syn::LitStr::new(&canonical_locale, proc_macro2::Span::call_site());
let canonical_message = crate::parse_fluent::message(&self.canonical_message);
parse_quote! {
{
#(if locale.normalizing_eq(#additional_locales) { return #additional_messages })else*
assert!(locale.normalizing_eq(#canonical_locale));
#canonical_message
}
}
}