add es lang

This commit is contained in:
lejianwen
2024-11-26 10:43:01 +08:00
parent 65571ab2f5
commit 287bbd43fb
2 changed files with 146 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package global
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-playground/locales/en" "github.com/go-playground/locales/en"
"github.com/go-playground/locales/es"
"github.com/go-playground/locales/ko" "github.com/go-playground/locales/ko"
"github.com/go-playground/locales/ru" "github.com/go-playground/locales/ru"
"github.com/go-playground/locales/zh_Hans_CN" "github.com/go-playground/locales/zh_Hans_CN"
@@ -10,6 +11,7 @@ import (
ut "github.com/go-playground/universal-translator" ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
en_translations "github.com/go-playground/validator/v10/translations/en" en_translations "github.com/go-playground/validator/v10/translations/en"
es_translations "github.com/go-playground/validator/v10/translations/es"
ru_translations "github.com/go-playground/validator/v10/translations/ru" ru_translations "github.com/go-playground/validator/v10/translations/ru"
zh_translations "github.com/go-playground/validator/v10/translations/zh" zh_translations "github.com/go-playground/validator/v10/translations/zh"
"reflect" "reflect"
@@ -23,13 +25,15 @@ func ApiInitValidator() {
cn := zh_Hans_CN.New() cn := zh_Hans_CN.New()
koT := ko.New() koT := ko.New()
ruT := ru.New() ruT := ru.New()
esT := es.New()
uni := ut.New(enT, cn, koT, ruT) uni := ut.New(enT, cn, koT, ruT, esT)
enTrans, _ := uni.GetTranslator("en") enTrans, _ := uni.GetTranslator("en")
zhTrans, _ := uni.GetTranslator("zh_Hans_CN") zhTrans, _ := uni.GetTranslator("zh_Hans_CN")
koTrans, _ := uni.GetTranslator("ko") koTrans, _ := uni.GetTranslator("ko")
ruTrans, _ := uni.GetTranslator("ru") ruTrans, _ := uni.GetTranslator("ru")
esTrans, _ := uni.GetTranslator("es")
err := zh_translations.RegisterDefaultTranslations(validate, zhTrans) err := zh_translations.RegisterDefaultTranslations(validate, zhTrans)
if err != nil { if err != nil {
@@ -49,6 +53,10 @@ func ApiInitValidator() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
err = es_translations.RegisterDefaultTranslations(validate, esTrans)
if err != nil {
panic(err)
}
validate.RegisterTagNameFunc(func(field reflect.StructField) string { validate.RegisterTagNameFunc(func(field reflect.StructField) string {
label := field.Tag.Get("label") label := field.Tag.Get("label")
@@ -115,6 +123,9 @@ func getTranslatorForLang(lang string) ut.Translator {
case "ru": case "ru":
trans, _ := Validator.UT.GetTranslator("ru") trans, _ := Validator.UT.GetTranslator("ru")
return trans return trans
case "es":
trans, _ := Validator.UT.GetTranslator("es")
return trans
case "en": case "en":
fallthrough fallthrough
default: default:

134
resources/i18n/es.toml Normal file
View File

@@ -0,0 +1,134 @@
[Test]
description = "test"
one = "prueba1"
other = "Prueba2 {{.P0}}"
[ParamsError]
description = "Params validation failed."
one = "La validación de los parámetros falló."
other = "La validación de los parámetros falló."
[OperationFailed]
description = "OperationFailed."
one = "La operación falló."
other = "La operación falló."
[OperationSuccess]
description = "OperationSuccess."
one = "La operación fue exitosa."
other = "La operación fue exitosa."
[ItemExists]
description = "Item already exists."
one = "El elemento ya existe."
other = "El elemento ya existe."
[ItemNotFound]
description = "Item not found."
one = "El elemento no fue encontrado."
other = "El elemento no fue encontrado."
[NoAccess]
description = "No access."
one = "Sin acceso."
other = "Sin acceso."
[UsernameOrPasswordError]
description = "Username or password error."
one = "Error de usuario o contraseña."
other = "Error de usuario o contraseña."
[SystemError]
description = "System error."
one = "Error del sistema."
other = "Error del sistema."
[ConfigNotFound]
description = "Config not found."
one = "Configuración no encontrada."
other = "Configuración no encontrada."
[OauthExpired]
description = "Oauth expired."
one = "Oauth expirado, por favor intente nuevamente."
other = "Oauth expirado, por favor intente nuevamente."
[OauthFailed]
description = "Oauth failed."
one = "Oauth falló."
other = "Oauth falló."
[OauthHasBindOtherUser]
description = "Oauth has bind other user."
one = "Oauth está vinculado a otro usuario."
other = "Oauth está vinculado a otro usuario."
[ParamIsEmpty]
description = "Param is empty."
one = "{{.P0}} está vacío."
other = "{{.P0}} está vacío."
[BindFail]
description = "Bind fail."
one = "Fallo al vincular."
other = "Fallo al vincular."
[BindSuccess]
description = "Bind success."
one = "Vinculación exitosa."
other = "Vinculación exitosa."
[OauthHasBeenSuccess]
description = "Oauth has been success."
one = "Oauth fue exitoso."
other = "Oauth fue exitoso."
[OauthSuccess]
description = "Oauth success."
one = "Oauth exitoso."
other = "Oauth exitoso."
[OauthRegisterSuccess]
description = "Oauth register success."
one = "Registro de Oauth exitoso."
other = "Registro de Oauth exitoso."
[OauthRegisterFailed]
description = "Oauth register failed."
one = "Registro de Oauth falló."
other = "Registro de Oauth falló."
[GetOauthTokenError]
description = "Get oauth token error."
one = "Error al obtener el token de Oauth."
other = "Error al obtener el token de Oauth."
[GetOauthUserInfoError]
description = "Get oauth user info error."
one = "Error al obtener la información del usuario de Oauth."
other = "Error al obtener la información del usuario de Oauth."
[DecodeOauthUserInfoError]
description = "Decode oauth user info error."
one = "Error al decodificar la información del usuario de Oauth."
other = "Error al decodificar la información del usuario de Oauth."
[OldPasswordError]
description = "Old password error."
one = "Error con la contraseña anterior."
other = "Error con la contraseña anterior."
[DefaultGroup]
description = "Default group"
one = "Grupo predeterminado"
other = "Grupo predeterminado"
[ShareGroup]
description = "Share group"
one = "Grupo compartido"
other = "Grupo compartido"
[RegisterClosed]
description = "Register closed."
one = "Registro cerrado."
other = "Registro cerrado."