-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller.go
53 lines (43 loc) · 1.47 KB
/
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
45
46
47
48
49
50
51
52
53
package i18n
import (
"strings"
"github.com/qor/admin"
"github.com/qor/qor/utils"
)
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
key := form.Get("Key")
locale := form.Get("Locale")
locale = strings.TrimLeft(locale, "admin_")
locale = strings.TrimLeft(locale, "supplier_")
adminValue := utils.HTMLSanitizer.Sanitize(form.Get("AdminValue"))
supplierValue := utils.HTMLSanitizer.Sanitize(form.Get("SupplierValue"))
displayId := utils.HTMLSanitizer.Sanitize(form.Get("Id"))
descriprion := utils.HTMLSanitizer.Sanitize(form.Get("Description"))
adminTranslation := Translation{Key: key, Locale: "admin_" + locale, Value: adminValue, DisplayId: displayId, Description: descriprion}
supplierTranslation := Translation{Key: key, Locale: "supplier_" + locale, Value: supplierValue, DisplayId: displayId, Description: descriprion}
var hasError bool
var errMessage string
err := controller.I18n.SaveTranslation(&adminTranslation)
if err != nil {
hasError = true
errMessage = err.Error()
}
err = controller.I18n.SaveTranslation(&supplierTranslation)
if err != nil {
hasError = true
errMessage = errMessage + "\n" + err.Error()
}
if !hasError {
context.Writer.Write([]byte("OK"))
} else {
context.Writer.WriteHeader(422)
context.Writer.Write([]byte(err.Error()))
}
}