Skip to content

Commit

Permalink
feat(i18n): Merge pull request #85 from jimmyGALLAND/trans-fr
Browse files Browse the repository at this point in the history
add locale french
  • Loading branch information
lejianwen authored Dec 22, 2024
2 parents a771b1e + 6faa515 commit 64f4a6d
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 1 deletion.
13 changes: 12 additions & 1 deletion global/apiValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/go-playground/locales/es"
"github.com/go-playground/locales/ko"
"github.com/go-playground/locales/ru"
"github.com/go-playground/locales/fr"
"github.com/go-playground/locales/zh_Hans_CN"

ut "github.com/go-playground/universal-translator"
Expand All @@ -14,6 +15,7 @@ import (
es_translations "github.com/go-playground/validator/v10/translations/es"
ru_translations "github.com/go-playground/validator/v10/translations/ru"
zh_translations "github.com/go-playground/validator/v10/translations/zh"
fr_translations "github.com/go-playground/validator/v10/translations/fr"
"reflect"
)

Expand All @@ -26,14 +28,16 @@ func ApiInitValidator() {
koT := ko.New()
ruT := ru.New()
esT := es.New()
frT := fr.New()

uni := ut.New(enT, cn, koT, ruT, esT)
uni := ut.New(enT, cn, koT, ruT, esT, frT)

enTrans, _ := uni.GetTranslator("en")
zhTrans, _ := uni.GetTranslator("zh_Hans_CN")
koTrans, _ := uni.GetTranslator("ko")
ruTrans, _ := uni.GetTranslator("ru")
esTrans, _ := uni.GetTranslator("es")
frTrans, _ := uni.GetTranslator("fr")

err := zh_translations.RegisterDefaultTranslations(validate, zhTrans)
if err != nil {
Expand All @@ -57,6 +61,10 @@ func ApiInitValidator() {
if err != nil {
panic(err)
}
err = fr_translations.RegisterDefaultTranslations(validate, frTrans)
if err != nil {
panic(err)
}

validate.RegisterTagNameFunc(func(field reflect.StructField) string {
label := field.Tag.Get("label")
Expand Down Expand Up @@ -126,6 +134,9 @@ func getTranslatorForLang(lang string) ut.Translator {
case "es":
trans, _ := Validator.UT.GetTranslator("es")
return trans
case "fr":
trans, _ := Validator.UT.GetTranslator("fr")
return trans
case "en":
fallthrough
default:
Expand Down
144 changes: 144 additions & 0 deletions resources/i18n/fr.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
[Test]
description = "test"
one = "test1 "
other = "Test2 {{.P0}}"

[ParamsError]
description = "Params validation failed."
one = "La validation des paramètres a échoué."
other = "La validation des paramètres a échoué."

[OperationFailed]
description = "OperationFailed."
one = "l'opération a échoué."
other = "l'opération a échoué."

[OperationSuccess]
description = "OperationSuccess."
one = "Opération réussie"
other = "Opération réussie"

[ItemExists]
description = "Item already exists."
one = "L'élément existe déjà."
other = "L'élément existe déjà."

[ItemNotFound]
description = "Item not found."
one = "Article introuvable."
other = "Article introuvable."

[NoAccess]
description = "No access."
one = "Aucun d'access."
other = "Aucun d'access."

[UsernameOrPasswordError]
description = "Username or password error."
one = "Nom d'utilisateur ou de mot de passe incorrect."
other = "Nom d'utilisateur ou de mot de passe incorrect."

[SystemError]
description = "System error."
one = "Erreur system."
other = "Erreur system."

[ConfigNotFound]
description = "Config not found."
one = "Configuration introuvable."
other = "Configuration introuvable."

[OauthExpired]
description = "Oauth expired."
one = "Oauth a expiré, veuillez réessayer."
other = "Oauth a expiré, veuillez réessayer."

[OauthFailed]
description = "Oauth failed."
one = "Oauth a échoué."
other = "Oauth a échoué."

[OauthHasBindOtherUser]
description = "Oauth has bind other user."
one = "Oauth a lié un autre utilisateur."
other = "Oauth a lié un autre utilisateur."

[ParamIsEmpty]
description = "Param is empty."
one = "{{.P0}} est vide."
other = "{{.P0}} est vide."

[BindFail]
description = "Bind fail."
one = "Échec de la liaison."
other = "Échec de la liaison."

[BindSuccess]
description = "Bind success."
one = "Succès de la liaison."
other = "Succès de la liaison."

[OauthHasBeenSuccess]
description = "Oauth has been success."
one = "Oauth a été réussi avec Succès."
other = "Oauth a été réussi avec Succès."

[OauthSuccess]
description = "Oauth success."
one = "Oauh réussi avec succès."
other = "Oauh réussi avec succès."

[OauthRegisterSuccess]
description = "Oauth register success."
one = "Succès de l'enregistrement Oauth."
other = "Succès de l'enregistrement Oauth."

[OauthRegisterFailed]
description = "Oauth register failed."
one = "L'inscription Oauth a échoué."
other = "L'inscription Oauth a échoué."

[GetOauthTokenError]
description = "Get oauth token error."
one = "Erreur de l'obtention du jeton oauth."
other = "Erreur de l'obtention du jeton oauth."

[GetOauthUserInfoError]
description = "Get oauth user info error."
one = "Erreur d'obtention d'informations sur l'utilisateur oauth."
other = "Erreur d'obtention d'informations sur l'utilisateur oauth."

[DecodeOauthUserInfoError]
description = "Decode oauth user info error."
one = "Erreur de décodage des informations utilisateur oauth."
other = "Erreur de décodage des informations utilisateur oauth."

[OldPasswordError]
description = "Old password error."
one = "Ancien mot de passe incorrect."
other = "Ancien mot de passe incorrect."

[DefaultGroup]
description = "Default group"
one = "Groupe Défaut"
other = "Groupe Défaut"

[ShareGroup]
description = "Share group"
one = "Groupe partagé"
other = "Groupe partagé"

[RegisterClosed]
description = "Register closed."
one = "Inscription fermée."
other = "Inscription fermée."

[CaptchaRequired]
description = "Captcha required."
one = "Captcha requis."
other = "Captcha requis."

[CaptchaError]
description = "Captcha error."
one = "Erreur de captcha."
other = "Erreur de captcha."

0 comments on commit 64f4a6d

Please sign in to comment.