From 46e8250f7ef5bcf664ffa8db752a17cfc370f340 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Fri, 15 Nov 2024 13:11:16 +0100 Subject: [PATCH] Fix component translation scopes 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. --- .../components/solidus_admin/base_component.rb | 4 ++++ .../orders/index/component.yml | 15 --------------- .../solidus_promotions/orders/index/component.yml | 2 ++ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/admin/app/components/solidus_admin/base_component.rb b/admin/app/components/solidus_admin/base_component.rb index 7bfe1b52852..e41e65235cf 100644 --- a/admin/app/components/solidus_admin/base_component.rb +++ b/admin/app/components/solidus_admin/base_component.rb @@ -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') diff --git a/legacy_promotions/lib/components/admin/solidus_legacy_promotions/orders/index/component.yml b/legacy_promotions/lib/components/admin/solidus_legacy_promotions/orders/index/component.yml index 454b31bbdb7..3829db2d825 100644 --- a/legacy_promotions/lib/components/admin/solidus_legacy_promotions/orders/index/component.yml +++ b/legacy_promotions/lib/components/admin/solidus_legacy_promotions/orders/index/component.yml @@ -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 diff --git a/promotions/lib/components/admin/solidus_promotions/orders/index/component.yml b/promotions/lib/components/admin/solidus_promotions/orders/index/component.yml index 95af3f495d4..3829db2d825 100644 --- a/promotions/lib/components/admin/solidus_promotions/orders/index/component.yml +++ b/promotions/lib/components/admin/solidus_promotions/orders/index/component.yml @@ -1,3 +1,5 @@ en: filters: promotions: Promotions + scopes: + promotions: Promotions