mirror of
https://github.com/tucnak/telebot
synced 2024-11-11 01:10:39 +00:00
25 lines
477 B
Go
25 lines
477 B
Go
package layout
|
|
|
|
import tele "gopkg.in/tucnak/telebot.v3"
|
|
|
|
func (lt *Layout) Middleware(defaultLocale string, localeFunc ...LocaleFunc) tele.MiddlewareFunc {
|
|
var f LocaleFunc
|
|
if len(localeFunc) > 0 {
|
|
f = localeFunc[0]
|
|
}
|
|
|
|
return func(next tele.HandlerFunc) tele.HandlerFunc {
|
|
return func(c tele.Context) error {
|
|
locale := defaultLocale
|
|
if f != nil {
|
|
if l := f(c.Sender()); l != "" {
|
|
locale = l
|
|
}
|
|
}
|
|
|
|
lt.ctxs[c] = locale
|
|
return next(c)
|
|
}
|
|
}
|
|
}
|