add i18n support

This commit is contained in:
landaiqing
2024-11-12 22:59:39 +08:00
parent 97ca3fc7b0
commit ae743ba8a6
62 changed files with 4468 additions and 2797 deletions

16
common/i18n/bundle.go Normal file
View File

@@ -0,0 +1,16 @@
package i18n
import (
i18n2 "github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/pelletier/go-toml/v2"
"golang.org/x/text/language"
)
func NewBundle(tag language.Tag, configs ...string) *i18n2.Bundle {
bundle := i18n2.NewBundle(tag)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
for _, file := range configs {
bundle.LoadMessageFile(file)
}
return bundle
}