日志初步结构
This commit is contained in:
@@ -21,7 +21,27 @@ func init() {
|
||||
globpath := filepath.Join(currentDir, "/*.toml")
|
||||
|
||||
Bundle = i18n.NewBundle(language.Chinese)
|
||||
Bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
||||
Bundle.RegisterUnmarshalFunc("toml", func(data []byte, v interface{}) error {
|
||||
var m map[string]any
|
||||
err := toml.Unmarshal(data, &m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, v := range m {
|
||||
vm := v.(map[string]any)
|
||||
desc := vm["description"].(string)
|
||||
vm["one"] = desc
|
||||
vm["other"] = desc
|
||||
}
|
||||
|
||||
fixdata, err := toml.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return toml.Unmarshal(fixdata, v)
|
||||
})
|
||||
matches, err := filepath.Glob(globpath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -30,14 +50,6 @@ func init() {
|
||||
Bundle.MustLoadMessageFile(m)
|
||||
}
|
||||
|
||||
// localizer := i18n.NewLocalizer(Bundle, "zh_cn")
|
||||
// log.Println(localizer.Localize(&i18n.LocalizeConfig{
|
||||
// MessageID: "format_account_is_insufficient",
|
||||
// TemplateData: map[string]any{
|
||||
// "CatalogCurrency": "USDT",
|
||||
// },
|
||||
// }))
|
||||
|
||||
}
|
||||
|
||||
func Localize(MessageID TrCode, Lang string, MessageTemplateParam any) (string, error) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"text/template"
|
||||
"unicode"
|
||||
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
@@ -118,7 +119,10 @@ func createTrCode(filePath string) {
|
||||
}
|
||||
|
||||
func TestTrOnline(t *testing.T) {
|
||||
|
||||
var localizer = i18n.NewLocalizer(Bundle, "zh_cn")
|
||||
log.Println(localizer.Localize(&i18n.LocalizeConfig{
|
||||
MessageID: string("account_not_registered"),
|
||||
}))
|
||||
}
|
||||
|
||||
func toCamelCase(s string) string {
|
||||
|
||||
@@ -280,5 +280,6 @@ description = "默认交易时间段"
|
||||
description = "非默认交易时间段"
|
||||
[all_day_transaction]
|
||||
description = "全天交易"
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user