Skip to content

Commit e259238

Browse files
mamhofftvdeyen
authored andcommitted
Use human_attribute_name for promo calculator labels
Promotion calculators have preferences, and these need to be translated with the correct scope. When you specify a preference for a calculator, a virtual attribute is generated. For example: ``` class MyCalculator < Spree::Calculator preference :percent, :integer, default: 10 end ``` In this scenario, we get a virtual attribute `preferred_percent` on the `MyCalculator` class. The expectation is that then one can translated that attribute by calling: `MyCalculator.human_attribute_name(:preferred_percent)`, and - crucially - that this attribute is used in form labels. While all other calculator forms use this (through `form.label :preferred_percent`) or similar, the default form did not, and instead used `I18n.t(:percent, scope: :spree)`, which is not specific to the calculator, and might lead to mistranslations.
1 parent 36c2646 commit e259238

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

promotions/config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ en:
311311
preferred_currency: Currency
312312
solidus_promotions/calculators/percent:
313313
description: Provides a discount calculated by percent of the discountable amount of the item being discounted
314+
preferred_percent: Percent
314315
solidus_promotions/calculators/distributed_amount:
315316
description: Distributes the configured amount among all eligible line items of the order.
316317
explanation: |
@@ -350,6 +351,7 @@ en:
350351
</tbody>
351352
</table>
352353
preferred_amount: Amount
354+
preferred_currency: Currency
353355

354356
errors:
355357
models:

promotions/lib/views/backend/solidus_promotions/admin/calculator_fields/_default_fields.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
<%= render "solidus_promotions/admin/shared/preference_fields/#{calculator.preference_type(name)}",
33
name: "#{prefix}[calculator_attributes][preferred_#{name}]",
44
value: calculator.get_preference(name),
5-
label: t(name.to_s, scope: 'spree', default: name.to_s.humanize) %>
5+
label: calculator.class.human_attribute_name("preferred_#{name}", default: I18n.t(name, scope: :spree, default: name.humanize)) %>
66
<% end %>

0 commit comments

Comments
 (0)