-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller.go
34 lines (27 loc) · 897 Bytes
/
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
package i18n
import (
"github.com/microcosm-cc/bluemonday"
"github.com/qor/admin"
)
var htmlSanitizer = bluemonday.UGCPolicy()
type i18nController struct {
*I18n
}
func (controller *i18nController) Index(context *admin.Context) {
context.Execute("index", controller.I18n)
}
func (controller *i18nController) Update(context *admin.Context) {
form := context.Request.Form
translation := Translation{Key: form.Get("Key"), Locale: form.Get("Locale"), Value: htmlSanitizer.Sanitize(form.Get("Value"))}
if results := controller.I18n.Translations[translation.Locale]; results != nil {
if result := results[translation.Key]; result != nil {
translation.Backend = result.Backend
}
}
if err := controller.I18n.SaveTranslation(&translation); err == nil {
context.Writer.Write([]byte("OK"))
} else {
context.Writer.WriteHeader(422)
context.Writer.Write([]byte(err.Error()))
}
}