-
Notifications
You must be signed in to change notification settings - Fork 13
/
localize.go
39 lines (34 loc) · 1.07 KB
/
localize.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"
"github.com/coretrix/hitrix/service/component/localize"
"github.com/sarulabs/di"
)
func ServiceProviderLocalize() *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: service.LocalizeService,
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 := localize.NewPoeditorSource(
apiKey,
projectID,
language,
)
return localize.NewSimpleLocalizer(apiSource), nil
},
}
}