diff --git a/lib/avo/resources/base.rb b/lib/avo/resources/base.rb index a215aa80f..4b3b342e4 100644 --- a/lib/avo/resources/base.rb +++ b/lib/avo/resources/base.rb @@ -54,7 +54,7 @@ def current_user class_attribute :single_includes, default: [] class_attribute :single_attachments, default: [] class_attribute :authorization_policy - class_attribute :translation_key + class_attribute :custom_translation_key class_attribute :default_view_type, default: :table class_attribute :devise_password_optional, default: false class_attribute :scopes_loader @@ -176,8 +176,9 @@ def singular_route_key end def translation_key - @translation_key || "avo.resource_translations.#{class_name.underscore}" + custom_translation_key || "avo.resource_translations.#{class_name.underscore}" end + alias_method :translation_key=, :custom_translation_key= def name name_from_translation_key(count: 1, default: class_name.underscore.humanize) @@ -254,6 +255,7 @@ def fetch_search(key, record: nil) delegate :to_param, to: :class delegate :find_record, to: :class delegate :model_key, to: :class + delegate :translation_key, to: :class delegate :tab, to: :items_holder def initialize(record: nil, view: nil, user: nil, params: nil) diff --git a/spec/dummy/app/avo/resources/course.rb b/spec/dummy/app/avo/resources/course.rb index ecc6e31a3..92c058077 100644 --- a/spec/dummy/app/avo/resources/course.rb +++ b/spec/dummy/app/avo/resources/course.rb @@ -5,6 +5,7 @@ class Avo::Resources::Course < Avo::BaseResource self.keep_filters_panel_open = true self.stimulus_controllers = "city-in-country toggle-fields" # self.default_sort_column = :country + self.translation_key = "test.translation_key.course" def show_fields fields_bag diff --git a/spec/dummy/config/locales/avo.pt.yml b/spec/dummy/config/locales/avo.pt.yml index ccced052e..59f5b159c 100644 --- a/spec/dummy/config/locales/avo.pt.yml +++ b/spec/dummy/config/locales/avo.pt.yml @@ -3,3 +3,9 @@ pt: avo: resource_translations: product: "Produto" + test: + translation_key: + course: + zero: cursos + one: curso + other: cursos diff --git a/spec/features/avo/i18n_spec.rb b/spec/features/avo/i18n_spec.rb index 0743598ab..867d48e76 100644 --- a/spec/features/avo/i18n_spec.rb +++ b/spec/features/avo/i18n_spec.rb @@ -21,4 +21,13 @@ expect(page).to have_button("Save the product!") end end + + describe "resource translation_key" do + it "apply translation_key" do + visit avo.resources_courses_path(force_locale: :pt) + + expect(page).to have_text("Cursos") + expect(page).to have_text("Criar novo curso") + end + end end