1234567891011121314151617181920212223242526272829303132 |
- 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)
- _, err := bundle.LoadMessageFile("static/locale/common.en.toml")
- if err != nil {
- panic(err)
- }
- _, err = bundle.LoadMessageFile("static/locale/common.zh.toml")
- if err != nil {
- panic(err)
- }
- slog.Info("setup trans ok")
- }
- func GetTrans(lang string) *i18n.Localizer {
- return i18n.NewLocalizer(bundle, lang)
- }
|