Open bodqhrohro opened 2 years ago
Same if I try to invoke it from a custom function:
use fluent_templates::{static_loader, FluentLoader, StaticLoader};
use unic_langid::langid;
use lazy_static::lazy_static;
use std::collections::HashMap;
use rocket_dyn_templates::tera::{Value, Error, Function};
...
static_loader! {
static LOCALES = {
locales: "./locales",
fallback_language: "en",
};
}
lazy_static! {
static ref FLUENT_LOADER: FluentLoader<&'static StaticLoader> = FluentLoader::new(&*LOCALES);
}
pub fn tera_function(args: &HashMap<String, Value>) -> Result<Value, Error> {
(*FLUENT_LOADER).with_default_lang(langid!("en")).call(args)
}
error[E0599]: the method `call` exists for struct `FluentLoader<&StaticLoader>`, but its trait bounds were not satisfied
--> src/l10n.rs:39:53
|
39 | (*FLUENT_LOADER).with_default_lang(langid!("en")).call(args)
| ^^^^ method cannot be called on `FluentLoader<&StaticLoader>` due to unsatisfied trait bounds
|
::: /home/bodqhrohro/.cargo/registry/src/github.com-1ecc6299db9ec823/fluent-templates-0.8.0/src/loader.rs:94:1
|
94 | pub struct FluentLoader<L> {
| --------------------------
| |
| doesn't satisfy `<_ as FnOnce<(&HashMap<std::string::String, rocket_dyn_templates::tera::Value>,)>>::Output = Result<rocket_dyn_templates::tera::Value, rocket_dyn_templates::tera::Error>`
| doesn't satisfy `_: Fn<(&HashMap<std::string::String, rocket_dyn_templates::tera::Value>,)>`
| doesn't satisfy `_: rocket_dyn_templates::tera::Function`
|
= note: the following trait bounds were not satisfied:
`<FluentLoader<&StaticLoader> as FnOnce<(&HashMap<std::string::String, rocket_dyn_templates::tera::Value>,)>>::Output = Result<rocket_dyn_templates::tera::Value, rocket_dyn_templates::tera::Error>`
which is required by `FluentLoader<&StaticLoader>: rocket_dyn_templates::tera::Function`
`FluentLoader<&StaticLoader>: Fn<(&HashMap<std::string::String, rocket_dyn_templates::tera::Value>,)>`
which is required by `FluentLoader<&StaticLoader>: rocket_dyn_templates::tera::Function`
Thank you for your issue! You just need to remove the FluentLoader::new
part, the loader should be able to be passed directly to the register_function
. We should also add a fluent loader impl for &T
as well as that would make your code work as is
the loader should be able to be passed directly to the register_function
Hmm, what do you mean? I tried
.attach(Template::custom(|engines| {
engines.tera.register_function("fluent", FluentLoader {
loader: &*LOCALES,
default_lang: langid!("en"),
});
}))
engines.tera.register_function("fluent", &*LOCALES);
engines.tera.register_function("fluent", *LOCALES);
, and neither of them works, as well as I can't find trait implementations for StaticLoader
itself, so I don't get how is that supposed to work.
I try to use the loader with
and get:
tera.rs
does not have anything public, is it even imported? Or maybe there is something wrong with the signature?