Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support template.Options for setting up missing key behavior #315

Closed
demsasha4yt opened this issue Dec 28, 2023 · 2 comments · Fixed by #317
Closed

Support template.Options for setting up missing key behavior #315

demsasha4yt opened this issue Dec 28, 2023 · 2 comments · Fixed by #317

Comments

@demsasha4yt
Copy link

Currently, there is no support to parse and execute templates with missing key options. https://github.com/nicksnyder/go-i18n/blob/main/v2/internal/template.go#L36C28-L36C28

As a result, it is not possible to return error if any variable is missing in render payload

Kindly consider supporting text/template options https://pkg.go.dev/text/template#Template.Option

"missingkey=default" or "missingkey=invalid"
The default behavior: Do nothing and continue execution.
If printed, the result of the index operation is the string
"".
"missingkey=zero"
The operation returns the zero value for the map type's element.
"missingkey=error"
Execution stops immediately with an error.

@nicksnyder
Copy link
Owner

Seems reasonable. If you want to open a PR I would review it.

@nicksnyder
Copy link
Owner

With 2.4.0 there is now a way to specify a Template.Option. Check out the release notes for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants