-
Notifications
You must be signed in to change notification settings - Fork 49
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
Cannot contain "{" and "}" in the parameter text when using func (t *translator) Add(key interface{}, text string, override bool) error #27
Comments
func (t *translator) Add(key interface{}, text string, override bool) error {
if _, ok := t.translations[key]; ok && !override {
return &ErrConflictingTranslation{locale: t.Locale(), key: key, text: text}
}
lb := strings.Count(text, "{")
rb := strings.Count(text, "}")
if lb != rb {
return &ErrMissingBracket{locale: t.Locale(), key: key, text: text}
}
trans := &transText{
text: text,
}
var idx int
for i := 0; i < lb; i++ {
s := "{" + strconv.Itoa(i) + "}"
idx = strings.Index(text, s)
if idx == -1 {
return &ErrBadParamSyntax{locale: t.Locale(), param: s, key: key, text: text}
}
trans.indexes = append(trans.indexes, idx)
trans.indexes = append(trans.indexes, idx+len(s))
}
...
} I think the code upon caused the problem, is there any workaround? I tried |
I am having this problem as well. Additionally, if you have just one of the |
Is there a reason that Go's own template var system wasn't used for interpolation (https://pkg.go.dev/text/template#hdr-Text_and_spaces), e.g. |
Cannot contain "{" and "}" in the message when using method
func (t *translator) Add(key interface{}, text string, override bool) error
I want to custom a password validitor with tag
valid-password
, which requires password can containsa-zA-Z0-9
and(~!@#$%^&*()[]{}|/?,.<>)
only, and I'm using the universal-translator to custom the error message when validate fails. The point is when the customed error message contains "{" and "}",there will be an error!The text was updated successfully, but these errors were encountered: