-
Notifications
You must be signed in to change notification settings - Fork 274
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
Help Using Funcs #206
Comments
@nicksnyder I've also encountered a panic when running Here's a simple case that triggers the problem. // funcs.go
package bug
import "text/template"
var Funcs = template.FuncMap{
"noop": func(x interface{}) interface{} {
return x
},
} // render.go
package bug
import "github.com/nicksnyder/go-i18n/v2/i18n"
func Render(m *i18n.Message) {
l := i18n.NewLocalizer(nil, "en")
l.Localize(&i18n.LocalizeConfig{
DefaultMessage: m,
Funcs: Funcs, // <- note, Funcs is define in another file
})
} However, it works just fine if I define // render.go
package bug
import (
"github.com/nicksnyder/go-i18n/v2/i18n"
"text/template"
)
var Funcs = template.FuncMap{
"noop": func(x interface{}) interface{} {
return x
},
}
func Render(m *i18n.Message) {
l := i18n.NewLocalizer(nil, "en")
l.Localize(&i18n.LocalizeConfig{
DefaultMessage: m,
Funcs: Funcs,
})
} It seems like a reasonable solution might be to just return from Would be happy to open a PR with a fix & a corresponding test case if you agree! |
Also, I'm not 100% sure if this problem is the same as the one jamesgoodhouse is seeing. It seems like it might be, but if you want me to open a separate issue for this let me know. |
@patgrasso Looks like you found a bug, thanks! Yes please open a PR if you can to fix this (and include tests). |
I have setup a
LocalizeConfig
to include aFuncs
definition. However, it's unclear how those are to be used. When I attempt to use a function I've defined in a template, I get a panic saying it is not defined.Is there additional documentation on how one uses these?
The text was updated successfully, but these errors were encountered: