nezha/service/singleton/l10n.go

34 lines
752 B
Go
Raw Normal View History

2022-04-27 11:51:45 -04:00
package singleton
import (
2022-04-29 12:48:39 -04:00
"log"
2022-04-27 11:51:45 -04:00
"github.com/BurntSushi/toml"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
"github.com/naiba/nezha/model"
2022-04-27 11:51:45 -04:00
)
var Localizer *i18n.Localizer
func InitLocalizer() {
bundle := i18n.NewBundle(language.Chinese)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
2022-04-29 12:48:39 -04:00
if _, exists := model.Languages[Conf.Language]; !exists {
log.Println("NEZHA>> language not exists:", Conf.Language)
2022-04-29 12:48:39 -04:00
Conf.Language = "zh-CN"
} else {
_, err := bundle.LoadMessageFile("resource/l10n/" + Conf.Language + ".toml")
2022-04-29 12:48:39 -04:00
if err != nil {
panic(err)
}
2022-04-27 22:17:38 -04:00
}
2022-04-29 12:48:39 -04:00
if _, err := bundle.LoadMessageFile("resource/l10n/zh-CN.toml"); err != nil {
2022-04-27 22:17:38 -04:00
panic(err)
}
Localizer = i18n.NewLocalizer(bundle, Conf.Language)
2022-04-27 11:51:45 -04:00
}