forked from gin-contrib/i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
41 lines (34 loc) · 838 Bytes
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package i18n
import (
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
)
// BundleCfg ...
type BundleCfg struct {
DefaultLanguage language.Tag
FormatBundleFile string
AcceptLanguage []language.Tag
RootPath string
UnmarshalFunc i18n.UnmarshalFunc
Loader Loader
}
type Loader interface {
LoadMessage(path string) ([]byte, error)
}
type LoaderFunc func(path string) ([]byte, error)
func (f LoaderFunc) LoadMessage(path string) ([]byte, error) { return f(path) }
// WithBundle ...
func WithBundle(config *BundleCfg) Option {
return func(g GinI18n) {
if config.Loader == nil {
config.Loader = defaultLoader
}
g.setBundle(config)
}
}
// WithGetLngHandle ...
func WithGetLngHandle(handler GetLngHandler) Option {
return func(g GinI18n) {
g.setGetLngHandler(handler)
}
}