l10n_model.go 637 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package models
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "github.com/qor5/admin/l10n"
  7. "gorm.io/gorm"
  8. )
  9. type L10nModel struct {
  10. gorm.Model
  11. Title string
  12. l10n.Locale
  13. }
  14. func (lm *L10nModel) PrimarySlug() string {
  15. return fmt.Sprintf("%v_%v", lm.ID, lm.LocaleCode)
  16. }
  17. func (lm *L10nModel) PrimaryColumnValuesBySlug(slug string) map[string]string {
  18. segs := strings.Split(slug, "_")
  19. if len(segs) != 2 {
  20. panic("wrong slug")
  21. }
  22. return map[string]string{
  23. "id": segs[0],
  24. "locale_code": segs[1],
  25. }
  26. }
  27. func (lm *L10nModel) PermissionRN() []string {
  28. return []string{"l10n_models", strconv.Itoa(int(lm.ID)), lm.LocaleCode}
  29. }