/
label.go
35 lines (26 loc) · 936 Bytes
/
label.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
package templatefunctions
import (
"context"
"flamingo.me/flamingo/v3/core/locale/domain"
"flamingo.me/flamingo/v3/framework/flamingo"
"flamingo.me/flamingo/v3/core/locale/application"
)
// LabelFunc is exported as a template function
type LabelFunc struct {
labelService *application.LabelService
logger flamingo.Logger
}
// Inject dependencies
func (tf *LabelFunc) Inject(labelService *application.LabelService, logger flamingo.Logger) {
tf.labelService = labelService
tf.logger = logger.WithField("module", "locale").WithField("category", "templatefunctions.label")
}
// Func template function factory
func (tf *LabelFunc) Func(context.Context) interface{} {
return func(key string, params ...interface{}) *domain.Label {
if len(params) > 0 {
tf.logger.Warn("Deprecated unsupported parameters given! Use the Setters provided by the returned Label " + key)
}
return tf.labelService.NewLabel(key)
}
}