nicksnyder / go-i18n

Translate your Go program into multiple languages.
MIT License
2.96k stars 271 forks source link

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

Closed demsasha4yt closed 8 months ago

demsasha4yt commented 9 months ago

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 commented 9 months ago

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

nicksnyder commented 8 months ago

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