Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
technic opened this issue Jul 17, 2020 · 2 comments
Closed
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@technic
Copy link
Contributor

technic commented Jul 17, 2020

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
Copy link
Owner

XAMPPRocky commented Jul 17, 2020

@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.

@XAMPPRocky XAMPPRocky added good first issue Good for newcomers help wanted Extra attention is needed labels Jul 17, 2020
technic added a commit to technic/fluent-templates that referenced this issue Jul 17, 2020
this makes lang argument optional by providing global default value

See XAMPPRocky#13
XAMPPRocky pushed a commit that referenced this issue Jul 18, 2020
* Default lang argument in Tera templates

this makes lang argument optional by providing global default value

See #13

* generate tests only for enabled features

before this commit tests generated for disabled features were empty

* add tests for defautlt lang feature

* documentation for with_default_lang
@technic
Copy link
Contributor Author

technic commented Jul 18, 2020

This is implemented in #14

@technic technic closed this as completed Jul 18, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants