This commit is contained in:
2025-10-09 00:11:34 +02:00
parent 1ead02ab69
commit 774756a747
20 changed files with 288 additions and 74 deletions

View File

@@ -0,0 +1,6 @@
InvalidCredentials = "Invalid credentials."
AuthenticationSuccess = "Authentication was a success."
ValidationRequired = "This field is required."
ValidationTooShort = "This field is too short. It should be at least %s characters."
ValidationTooLong = "This field is too long. It should be under %s characters."
ValidationPropertyFail = "Validation failed for '%s' property."

View File

@@ -0,0 +1,6 @@
InvalidCredentials = "Identifiants invalides."
AuthenticationSuccess = "Connexion réussie."
ValidationRequired = "Ce champ est requis."
ValidationTooShort = "Ce champ est trop court. Il devrait contenir au moins %s caractères."
ValidationTooLong = "Ce champ est trop long. Il ne devrait pas dépasser %s caractères."
ValidationPropertyFail = "La validation a échoué pour la propriété '%s'."

View File

@@ -0,0 +1,32 @@
package i18nresource
import (
"embed"
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/pelletier/go-toml"
"golang.org/x/text/language"
)
//go:embed locale.*.toml
var localeFS embed.FS
func InitializeI18n() *i18n.Bundle {
bundle := i18n.NewBundle(language.English)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
bundle.LoadMessageFileFS(localeFS, "locale.en.toml")
bundle.LoadMessageFileFS(localeFS, "locale.fr.toml")
return bundle
}
func GetTranslatedMessage(ac appcontext.AppContext, messageID string) string {
localizer := i18n.NewLocalizer(ac.I18n, ac.C.GetHeader("Accept-Language"))
message, err := localizer.LocalizeMessage(&i18n.Message{
ID: messageID,
})
if err != nil {
message = err.Error()
}
return message
}