1
0
forked from Plemya-x/ALR

feat: add new logger and translation

This commit is contained in:
2025-01-22 14:40:11 +03:00
parent 945f920654
commit ac35b4d71d
10 changed files with 502 additions and 160 deletions

View File

@ -22,8 +22,13 @@ package translations
import (
"context"
"embed"
"io/fs"
"os"
"path"
"sync"
"github.com/jeandeaual/go-locale"
"github.com/leonelquinteros/gotext"
"go.elara.ws/logger"
"go.elara.ws/translate"
"golang.org/x/text/language"
@ -56,3 +61,25 @@ func Translator(ctx context.Context) *translate.Translator {
func NewLogger(ctx context.Context, l logger.Logger, lang language.Tag) *translate.TranslatedLogger {
return translate.NewLogger(l, *Translator(ctx), lang)
}
//go:embed po
var poFS embed.FS
func Setup() {
userLanguage, err := locale.GetLanguage()
if err != nil {
panic(err)
}
_, err = fs.Stat(poFS, path.Join("po", userLanguage))
if err != nil {
if os.IsNotExist(err) {
return
}
panic(err)
}
loc := gotext.NewLocaleFSWithPath(userLanguage, &poFS, "po")
loc.SetDomain("default")
gotext.SetLocales([]*gotext.Locale{loc})
}