XAMPPRocky / fluent-templates

Easily add Fluent to your Rust project.
Apache License 2.0
136 stars 28 forks source link

Feature request: configurable path to lang (in context) #51

Open sverro2 opened 1 year ago

sverro2 commented 1 year ago

It would be useful if the 'lang' template context path is configurable when registering a fluent helper. If I pass a common context object to every template I use fluent with, I could for example promise the lang data can be found at {{ my_context_object.language }} instead of {{ lang }}: handlebars.register_helper("fluent", Box::new(FluentLoader::new(&*LOCALES, "my_context_object.language")));

I know this makes code in this lib a bit more complex, but it definitely will make my project using this library cleaner.

Why would someone want this? Well, I already inserted an object containing lots of common data into the context (including language). I just want it to read that object, instead of having to clone the lang data to another field in the context.

It is one line of code less, for every route in my project (nice). But even nicer... currently if I forget to pass this variable to the 'context!' it will just use the fallback language, and I don't even get a compiler warning! If I forget to pass the common object, it's a lot easier to spot :D

Thanks for reading!