Skip to content

Commit

Permalink
Fix component translation scopes
Browse files Browse the repository at this point in the history
In the `view_component` gem, the `i18n_scope` for a component depends on
the file name of the component, and removes `app_components` and
everything before that in order to construct a scope.

This fails to work with components that live in `lib/components/admin/`,
as with our extensions, as there is no `app/components` in the path to
these components.

This change uses the class name instead, which should be easier on
memory and correctly works with components from solidus extensions.

This also fixes translations in inherited components, allowing to delete
some redundant translations in the promotion gem's `order` component.
  • Loading branch information
mamhoff committed Nov 15, 2024
1 parent e6e0243 commit 46e8250
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
4 changes: 4 additions & 0 deletions admin/app/components/solidus_admin/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def missing_translation(key, options)
end
end

def self.i18n_scope
@i18n_scope ||= name.underscore.tr("/", ".")
end

def self.stimulus_id
@stimulus_id ||= name.underscore
.sub(/^solidus_admin\/(.*)\/component$/, '\1')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
en:
columns:
items:
one: 1 Item
other: '%{count} Items'
filters:
status: Status
shipment_state: Shipment State
payment_state: Payment State
promotions: Promotions
date:
formats:
short: '%d %b %y'
scopes:
all_orders: All
canceled: Canceled
complete: Complete
returned: Returned
in_progress: In Progress
promotions: Promotions
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
en:
filters:
promotions: Promotions
scopes:
promotions: Promotions

0 comments on commit 46e8250

Please sign in to comment.