Skip to content

Commit

Permalink
add id and translations to Export Translations
Browse files Browse the repository at this point in the history
  • Loading branch information
zealllot committed Mar 13, 2019
1 parent 50f7049 commit b15cf55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (controller *i18nController) Index(context *admin.Context) {

func (controller *i18nController) Update(context *admin.Context) {
form := context.Request.Form
translation := Translation{Key: form.Get("Key"), Locale: form.Get("Locale"), Value: utils.HTMLSanitizer.Sanitize(form.Get("Value")), DisplayId: utils.HTMLSanitizer.Sanitize(form.Get("DisplayId")), Description: utils.HTMLSanitizer.Sanitize(form.Get("Description"))}
translation := Translation{Key: form.Get("Key"), Locale: form.Get("Locale"), Value: utils.HTMLSanitizer.Sanitize(form.Get("Value")), DisplayId: utils.HTMLSanitizer.Sanitize(form.Get("Id")), Description: utils.HTMLSanitizer.Sanitize(form.Get("Description"))}

fmt.Println("出现了")
fmt.Println(translation)
Expand Down
13 changes: 11 additions & 2 deletions exchange_actions/exchange_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"time"

"github.com/qor/admin"
"github.com/zealllot/i18n"
"github.com/qor/media/oss"
"github.com/qor/worker"
"github.com/zealllot/i18n"
)

type ExportTranslationArgument struct {
Expand Down Expand Up @@ -74,7 +74,7 @@ func RegisterExchangeJobs(I18n *i18n.I18n, Worker *worker.Worker) {
writer := csv.NewWriter(csvfile)

// Append Headers
writer.Write(append([]string{"Translation Keys"}, locales...))
writer.Write(append([]string{"Translation Keys"}, append(locales, []string{"Id", "Description"}...)...))

// Sort translation keys
for _, locale := range locales {
Expand Down Expand Up @@ -106,13 +106,22 @@ func RegisterExchangeJobs(I18n *i18n.I18n, Worker *worker.Worker) {
continue
}
var translations = []string{translationKey}
var id string
var description string
for _, locale := range locales {
var value string
if translation := i18nTranslations[locale][translationKey]; translation != nil {
value = translation.Value
if translation.DisplayId != "" {
id = translation.DisplayId
}
if translation.Description != "" {
description = translation.Description
}
}
translations = append(translations, value)
}
translations = append(translations, []string{id, description}...)
writer.Write(translations)
processedRecordLogs = append(processedRecordLogs, fmt.Sprintf("Exported %v\n", strings.Join(translations, ",")))
if index == perCount {
Expand Down

0 comments on commit b15cf55

Please sign in to comment.