generated from fluffy-bunny/fluffycore-grpc-starterkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
localizer.go
37 lines (32 loc) · 1018 Bytes
/
localizer.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
package localizer
import (
di "github.com/fluffy-bunny/fluffy-dozm-di"
contracts_localizer "github.com/fluffy-bunny/fluffycore-rage-identity/pkg/contracts/localizer"
echo "github.com/labstack/echo/v4"
i18n "github.com/nicksnyder/go-i18n/v2/i18n"
)
type (
service struct {
bundle contracts_localizer.ILocalizerBundle
localizer *i18n.Localizer
}
)
var stemService = (*service)(nil)
func init() {
var _ contracts_localizer.ILocalizer = stemService
}
func (s *service) Ctor(bundle contracts_localizer.ILocalizerBundle) (contracts_localizer.ILocalizer, error) {
return &service{
bundle: bundle,
}, nil
}
func AddScopedILocalizer(cb di.ContainerBuilder) {
di.AddScoped[contracts_localizer.ILocalizer](cb, stemService.Ctor)
}
func (s *service) GetLocalizer() *i18n.Localizer {
return s.localizer
}
func (s *service) Initialize(c echo.Context) {
accept := c.Request().Header.Get("Accept-Language")
s.localizer = i18n.NewLocalizer(s.bundle.GetBundle(), accept)
}