2019-12-02 09:57:14 -05:00
|
|
|
package main
|
|
|
|
|
2021-09-29 07:58:02 -04:00
|
|
|
import (
|
2022-03-24 08:22:05 -04:00
|
|
|
"fmt"
|
2021-09-29 07:58:02 -04:00
|
|
|
|
2022-04-27 11:51:45 -04:00
|
|
|
"github.com/naiba/nezha/service/singleton"
|
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
|
|
"golang.org/x/text/language"
|
2021-09-29 07:58:02 -04:00
|
|
|
)
|
2019-12-02 09:57:14 -05:00
|
|
|
|
2022-04-27 11:51:45 -04:00
|
|
|
func htmlTemplateTranslateFn(id string, data interface{}, count interface{}) string {
|
|
|
|
return singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: id,
|
|
|
|
TemplateData: data,
|
|
|
|
PluralCount: count,
|
|
|
|
})
|
2022-03-24 08:22:05 -04:00
|
|
|
}
|
|
|
|
|
2019-12-02 09:57:14 -05:00
|
|
|
func main() {
|
2022-04-27 11:51:45 -04:00
|
|
|
singleton.InitLocalizer()
|
|
|
|
fmt.Println(singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "nezhaMonitor",
|
|
|
|
}))
|
2022-03-24 08:22:05 -04:00
|
|
|
|
2022-04-27 11:51:45 -04:00
|
|
|
fmt.Println(singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "nezhaMonitor",
|
|
|
|
}))
|
2022-03-24 08:22:05 -04:00
|
|
|
|
2022-04-27 11:51:45 -04:00
|
|
|
fmt.Println("tr nezhaMonitor", htmlTemplateTranslateFn("nezhaMonitor", nil, nil))
|
|
|
|
fmt.Println("tr nezhaMonitor", htmlTemplateTranslateFn("nezhaMonitor", nil, 2))
|
|
|
|
fmt.Println("tr nezhaMonitor", htmlTemplateTranslateFn("nezhaMonitor", map[string]string{
|
|
|
|
"Ext": "Plus",
|
|
|
|
}, 2))
|
|
|
|
|
|
|
|
bundle := i18n.NewBundle(language.English)
|
|
|
|
localizer := i18n.NewLocalizer(bundle, "en")
|
|
|
|
catsMessage := &i18n.Message{
|
|
|
|
ID: "Cats",
|
|
|
|
One: "I have {{.PluralCount}} cat.",
|
|
|
|
Other: "I have {{.PluralCount}} cats.",
|
|
|
|
}
|
|
|
|
fmt.Println(localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
DefaultMessage: catsMessage,
|
|
|
|
PluralCount: 1,
|
|
|
|
}))
|
|
|
|
fmt.Println(localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
DefaultMessage: catsMessage,
|
|
|
|
PluralCount: 2,
|
|
|
|
}))
|
2019-12-02 09:57:14 -05:00
|
|
|
}
|