-
Notifications
You must be signed in to change notification settings - Fork 266
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
Add HasFunc eqvlt to TFunc #56
Comments
So HasFunc would return a boolean true/false if a translation exists or not? |
yes. I also have been thinking to a sort of |
Couple questions:
Tfunc should return the translation id, not an empty response if a translation doesn't exist. Can you share your code?
If this function existed, would you still want/need HasFunc?
I don't quite see how there is a better way than checking the ids one by one in priority order. |
1/ Right! mistake of mine. func (f *FormTranslator) TError(formName string, fErr *FormValidationError) template.HTML {
ids := []string{
strings.ToLower(formName+"-"+fErr.Field+"-"+fErr.Tag),
strings.ToLower(fErr.Ns+"-"+fErr.Tag),
strings.ToLower(fErr.Field+"-"+fErr.Tag),
strings.ToLower("form_error-"+fErr.Tag),
}
for _,id := range ids {
m := f.T(id, fErr) //todo, escape fErr.Value.
if m!="" && m!=id {
return template.HTML(m)
}
}
return template.HTML(f.missingTranslation(formName, fErr))
} 2/ If this function existed, would you still want/need HasFunc? no 3/ there is this code that would be redundant. 4/ btw, language detection could be handled into TfuncAndLanguage, no ? |
I think this will be solved/obsolete with v2 proposed in #92 |
sure, thanks. |
I just tagged 2.0.0.beta.1. Please start using it and report any issues that you have. |
Hi,
In one particular situation i want to translate some materials using a cascade of IDs.
Specifically for form error handling.
Reason for that is to be able to have a general translation, and if needed a set of more and more specific translations ID alternative for that specific (input + error) of that specific (form+input+error).
Right now i m doing it by trying to translate each possibility until it returns non empty value which is considered as the translation to consume.
I d prefer to use a
HasFunc(ID)
to remove that test on empty response.what do you think ?
The text was updated successfully, but these errors were encountered: