diff --git a/lib/avo/resources/base.rb b/lib/avo/resources/base.rb index a215aa80f..bb2bcf42b 100644 --- a/lib/avo/resources/base.rb +++ b/lib/avo/resources/base.rb @@ -54,7 +54,6 @@ def current_user class_attribute :single_includes, default: [] class_attribute :single_attachments, default: [] class_attribute :authorization_policy - class_attribute :translation_key class_attribute :default_view_type, default: :table class_attribute :devise_password_optional, default: false class_attribute :scopes_loader @@ -175,10 +174,6 @@ def singular_route_key route_key.singularize end - def translation_key - @translation_key || "avo.resource_translations.#{class_name.underscore}" - end - def name name_from_translation_key(count: 1, default: class_name.underscore.humanize) end @@ -246,6 +241,8 @@ def fetch_search(key, record: nil) end end + class_attribute :translation_key, default: "avo.resource_translations.#{class_name.underscore}" + delegate :context, to: ::Avo::Current delegate :name, to: :class delegate :singular_name, to: :class 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