Go-playground/validator: support multiple languages for translations

Hello all,

I’m following this example to enable translations for validation errors.
The example works but I don’t understand how to add support for multiple translations.

My application is a HTTP REST backend and the language to be used for translation is detected reading the Accept-Language header of the HTTP request.

My main problem is that also if I register multiple languages with

uni = ut.New(en, en, it.New(), fr.New())

the language used for translations is always en also if in my handler I do

trans, _ := uni.GetTranslator("it")

errs := err.(validator.ValidationErrors)
errs.Translate(trans)

I checked that calling

trans, found := uni.GetTranslator("it")

the value of found is true.

Any tips?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.