Skip to content

Commit

Permalink
fix: translation_key class attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Dec 31, 2024
1 parent 3f9f33f commit 9d4858a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/avo/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
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 9d4858a

Please sign in to comment.