Skip to content

Commit

Permalink
fix: translation_key class attribute (#3565)
Browse files Browse the repository at this point in the history
* fix: translation_key class attribute

* alias method approach

* delegate translation_key to class
  • Loading branch information
Paul-Bob authored Jan 7, 2025
1 parent 85cbb77 commit ad05ff8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/avo/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions spec/dummy/app/avo/resources/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/dummy/config/locales/avo.pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ pt:
avo:
resource_translations:
product: "Produto"
test:
translation_key:
course:
zero: cursos
one: curso
other: cursos
9 changes: 9 additions & 0 deletions spec/features/avo/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ad05ff8

Please sign in to comment.