-
Notifications
You must be signed in to change notification settings - Fork 7
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
i18n package for zog #26
Comments
@cachesdev has agreed to help handle some of the translations! |
I was thinking about this, and there are many ways we can proceed, you can always go with a direct translation where the types are translated. in example, a string will become "cadena" a number will become "numero" and so on, or you could refer only to the types in english, while keeping the message in the target language. the third option is to say "field" or "campo" instead of the type itself, but this assumes validation for a form, zog can be used in more than just form validation. // translate types Cadena
p.ErrCodeMin: "la cadena debe contener al menos {{min}} caracter(es)",
// Original type
p.ErrCodeMin: "string debe contener al menos {{min}} caracter(es)",
// Refer to it as a field
p.ErrCodeMin: "el campo debe contener al menos {{min}} caracter(es)", in Latam we usually refer to the translated version of types, not the original english terms. in a conversation it would be normal to talk about "cadenas, booleanos, mapas y listas" so the direct translation has some merit. |
I think you are right about direct translation being the right approach. Ideally I would like for this errors to be fine to display to non technical users. The reason field is not being used and instead the type name is being used is because:
|
I have the start of a working version for the i18n package. I'll hopefully push it up today and you can take a look at it. The main idea is:
This way if you need to support spanish and english you would do something like this: zi18n.SetLanguagesMap(map[string]conf.LangMap["es": zes.Map, "en": zen.Map,], "en") // default lang = en Then when you parse: errs := schema.Parse(data, &dest, z.withCtxValue("lang", "es")) |
@cachesdev Its ready. You can see the PR at #28 |
that looks good. so by the looks of it a language package will only export a variable |
Yes. That would be amazing! @cachesdev |
I also still need to add documentation and move the en lang map before mergin that PR |
@Oudwins opened the PR |
RESOLVED IN #28 |
The idea is to go one step futher in supporting i18n and have an actual small package dedicated to this. It will have a function that takes a language map and will server default errors based on that map.
Currently it is only planned to support the translation to spanish
The text was updated successfully, but these errors were encountered: