interface.go 558 B

12345678910111213141516171819202122232425262728293031
  1. package l10n
  2. import (
  3. "context"
  4. "reflect"
  5. "github.com/qor5/admin/utils"
  6. )
  7. type L10nInterface interface {
  8. SetLocale(locale string)
  9. GetLocale() string
  10. }
  11. func IsLocalizable(obj interface{}) (isLocalizable bool) {
  12. _, isLocalizable = utils.GetStruct(reflect.TypeOf(obj)).(L10nInterface)
  13. return
  14. }
  15. func IsLocalizableFromCtx(ctx context.Context) (localeCode string, isLocalizable bool) {
  16. locale := ctx.Value(LocaleCode)
  17. if locale != nil {
  18. localeCode = locale.(string)
  19. isLocalizable = true
  20. }
  21. return
  22. }
  23. type L10nONInterface interface {
  24. L10nON()
  25. }