feat(core): slightly optimized tr! macro

This commit is contained in:
Observer KRypt0n_ 2023-07-31 20:23:25 +02:00
parent 7492aad669
commit 06db94de58
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2

View file

@ -109,15 +109,14 @@ macro_rules! tr {
use fluent_templates::Loader;
use fluent_templates::fluent_bundle::FluentValue;
let mut args = std::collections::HashMap::new();
for (key, value) in $args {
args.insert(key, FluentValue::from(value));
}
#[allow(unused_unsafe)]
$crate::i18n::LOCALES
.lookup_with_args(unsafe { &$crate::i18n::LANG }, $id, &args)
.lookup_with_args(
unsafe { &$crate::i18n::LANG },
$id,
&std::collections::HashMap::from_iter($args.into_iter()
.map(|(key, value)| (key, FluentValue::from(value))))
)
.expect(&format!("Failed to find a message with given id: {}", stringify!($id)))
}
};