12345678910111213141516171819202122232425262728293031 |
- package common
- import (
- "log/slog"
- )
- import (
- "github.com/nicksnyder/go-i18n/v2/i18n"
- "github.com/pelletier/go-toml/v2"
- "golang.org/x/text/language"
- )
- var bundle *i18n.Bundle
- func SetupTrans() {
- slog.Info("setup trans")
- bundle = i18n.NewBundle(language.English)
- bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
- for _, filename := range MetadataConfig.Locales {
- slog.Info("loading locale", "filename", filename)
- _, err := bundle.LoadMessageFile(filename)
- if err != nil {
- panic(err)
- }
- }
- slog.Info("setup trans ok")
- }
- func GetTrans(lang string) *i18n.Localizer {
- return i18n.NewLocalizer(bundle, lang)
- }
|