-
Notifications
You must be signed in to change notification settings - Fork 13
/
localizer.go
39 lines (34 loc) · 1.09 KB
/
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
38
39
package registry
import (
"errors"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/config"
localizer "github.com/coretrix/hitrix/service/component/localizer"
"github.com/sarulabs/di"
)
func ServiceProviderLocalizer() *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: service.LocalizerService,
Build: func(ctn di.Container) (interface{}, error) {
configService := ctn.Get(service.ConfigService).(config.IConfig)
apiKey, ok := configService.String("translation.poeditor.api_key")
if !ok {
return nil, errors.New("missing translation.poeditor.api_key")
}
projectId, ok := configService.String("translation.poeditor.project_id")
if !ok {
return nil, errors.New("missing translation.poeditor.project_id")
}
language, ok := configService.String("translation.poeditor.language")
if !ok {
return nil, errors.New("missing translation.poeditor.language")
}
apiSource := localizer.NewPoeditorSource(
apiKey,
projectId,
language,
)
return localizer.NewSimpleLocalizer(apiSource), nil
},
}
}