XAMPPRocky / fluent-templates

Easily add Fluent to your Rust project.
Apache License 2.0
137 stars 29 forks source link

Passing lang argument to each call in tera template is not practical #13

Closed technic closed 4 years ago

technic commented 4 years ago

Hi,

I need to put same language argument in all function invocation in the Tera template. This looks like unnecessary boilerplate, because the language argument is always the same. Ideally the language should be a global variable of FluentLoader (or its "successor"). Then the language can be set before call to render function of tera template.

Unfortunately I don't think that it is possible to access context of tera template from the tera function, so we need to have another mutable state on the side.

XAMPPRocky commented 4 years ago

@technic Thank you for your issue! I've also thought about this as well. I would be willing to accept a PR that changes tera helper to optionally accept a default language on initialisation that makes lang optional. You'll have to rebuild the helper if you want to change the default, but I feel like that is an acceptable compromise since most people will only set it once.

technic commented 4 years ago

This is implemented in #14