2024-05-07 23:45:28 +03:00
|
|
|
package locale
|
|
|
|
|
2024-05-13 16:57:55 +03:00
|
|
|
import (
|
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
|
|
"golang.org/x/text/language"
|
|
|
|
)
|
2024-05-07 23:45:28 +03:00
|
|
|
|
|
|
|
type Localizer interface {
|
|
|
|
Message(string) string
|
2024-05-10 11:46:43 +03:00
|
|
|
Template(string, interface{}) string
|
2024-05-13 16:57:55 +03:00
|
|
|
Tag() language.Tag
|
2024-05-07 23:45:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type localizer struct {
|
|
|
|
loc *i18n.Localizer
|
2024-05-13 16:57:55 +03:00
|
|
|
tag language.Tag
|
2024-05-07 23:45:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *localizer) Message(str string) string {
|
|
|
|
return l.Template(str, nil)
|
|
|
|
}
|
|
|
|
|
2024-05-10 11:46:43 +03:00
|
|
|
func (l *localizer) Template(str string, tpl interface{}) string {
|
2024-05-07 23:45:28 +03:00
|
|
|
return l.loc.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: str,
|
|
|
|
TemplateData: tpl,
|
|
|
|
})
|
|
|
|
}
|
2024-05-13 16:57:55 +03:00
|
|
|
|
|
|
|
func (l *localizer) Tag() language.Tag {
|
|
|
|
return l.tag
|
|
|
|
}
|