-
Notifications
You must be signed in to change notification settings - Fork 51
/
translation_controller.go
44 lines (36 loc) · 1.09 KB
/
translation_controller.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
42
43
44
package controllers
import (
"context"
"flamingo.me/flamingo/v3/core/locale/application"
"flamingo.me/flamingo/v3/framework/web"
)
// TranslationController to be used to return translations for all labels as array
type TranslationController struct {
responder *web.Responder
labelService *application.LabelService
}
// TranslationJSON helper struct to map the result
type TranslationJSON struct {
Key string `json:"key"`
Translation string `json:"translation"`
}
// Inject dependencies
func (c *TranslationController) Inject(
responder *web.Responder,
labelService *application.LabelService,
) {
c.responder = responder
c.labelService = labelService
}
// GetAllTranslations controller for TranslationController
func (c *TranslationController) GetAllTranslations(ctx context.Context, r *web.Request) web.Result {
l := c.labelService.AllLabels()
translations := make([]TranslationJSON, 0, len(l))
for _, la := range l {
translations = append(translations, TranslationJSON{
Key: la.GetKey(),
Translation: la.String(),
})
}
return c.responder.Data(translations)
}