improved error handling on translation
All checks were successful
Generate check / check-changes (pull_request) Successful in 18s
Quality / check-changes (pull_request) Successful in 17s
Generate check / verify-generate (pull_request) Has been skipped
Quality / run-tests (pull_request) Successful in 30s

This commit is contained in:
2025-12-04 16:59:20 +00:00
parent 10e1e99683
commit 0d97432c6c

View File

@@ -4,6 +4,7 @@ import (
"embed"
"encoding/json"
"fmt"
"log/slog"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
@@ -38,9 +39,14 @@ func NewLocalizer(lang string) (*Localizer, error) {
}
func (t Localizer) Translate(key string, count int, values map[string]any) string {
return t.MustLocalize(&i18n.LocalizeConfig{
txt, err := t.Localize(&i18n.LocalizeConfig{
MessageID: key,
TemplateData: values,
PluralCount: count,
})
if err != nil {
slog.Error("failed to translate message", slog.Any("err", err))
return "<ERROR>"
}
return txt
}