lib/avo/base_resource.rb in avo-1.16.3 vs lib/avo/base_resource.rb in avo-1.16.4
- old
+ new
@@ -14,10 +14,11 @@
class_attribute :search_query, default: nil
class_attribute :search_query_help, default: ''
class_attribute :includes, default: []
class_attribute :model_class
class_attribute :translation_key
+ class_attribute :translation_enabled
class_attribute :default_view_type, default: :table
class_attribute :devise_password_optional, default: false
class_attribute :actions_loader
class_attribute :filters_loader
class_attribute :fields
@@ -92,11 +93,11 @@
def get_field_definitions
return [] if self.class.fields.blank?
fields = self.class.fields.map do |field|
- field.hydrate(resource: self, panel_name: default_panel_name, user: user)
+ field.hydrate(resource: self, panel_name: default_panel_name, user: user, translation_enabled: translation_enabled)
end
if Avo::App.license.lacks_with_trial(:custom_fields)
fields = fields.reject do |field|
field.custom?
@@ -190,37 +191,47 @@
in_panel: true
}
]
end
+ def class_name_without_resource
+ self.class.name.demodulize.chomp("Resource")
+ end
+
def model_class
return self.class.model_class if self.class.model_class.present?
return @model.class if @model.present?
- self.class.name.demodulize.chomp("Resource").safe_constantize
+ class_name_without_resource.safe_constantize
end
def model_title
return @model.send title if @model.present?
name
end
+ def translation_key
+ return "avo.resource_translations.#{class_name_without_resource.underscore}" if self.class.translation_enabled
+
+ self.class.translation_key
+ end
+
def name
return @name if @name.present?
- return I18n.t(self.class.translation_key, count: 1).capitalize if self.class.translation_key
+ return I18n.t(translation_key, count: 1).capitalize if translation_key
- self.class.name.demodulize.chomp("Resource").titlecase
+ class_name_without_resource.titlecase
end
def singular_name
name
end
def plural_name
- return I18n.t(self.class.translation_key, count: 2).capitalize if self.class.translation_key
+ return I18n.t(translation_key, count: 2).capitalize if translation_key
name.pluralize
end
def underscore_name