From ddc788ed5de52a4662d41223a65c2fb07bf676d3 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 24 Jan 2019 03:06:14 +0800 Subject: [PATCH] Move data representation translations to class --- .../data_representations/coordinator_fee.rb | 4 ++-- .../data_representations/exchange_order_fee.rb | 6 +++--- .../data_representations/payment_method_fee.rb | 4 +++- .../data_representations/shipping_method_fee.rb | 6 ++++-- .../data_representations/using_enterprise_fee.rb | 4 +++- .../data_representations/with_i18n.rb | 15 +++++++++++++++ .../reports/enterprise_fee_summary/summarizer.rb | 4 ---- 7 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/with_i18n.rb diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb index eac30edc66..a4ddd74f9f 100644 --- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb +++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb @@ -9,12 +9,12 @@ module OrderManagement include UsingEnterpriseFee def fee_calculated_on_transfer_through_name - context.i18n_translate("fee_calculated_on_transfer_through_all") + i18n_translate("fee_calculated_on_transfer_through_all") end def tax_category_name return context.data["tax_category_name"] if context.data["tax_category_name"].present? - context.i18n_translate("tax_category_various") if inherits_tax_category? + i18n_translate("tax_category_various") if inherits_tax_category? end def inherits_tax_category? diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/exchange_order_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/exchange_order_fee.rb index 2e33fb0649..87385bc0b8 100644 --- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/exchange_order_fee.rb +++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/exchange_order_fee.rb @@ -9,12 +9,12 @@ module OrderManagement include UsingEnterpriseFee def fee_calculated_on_transfer_through_name - context.i18n_translate("fee_calculated_on_transfer_through_entire_orders", - distributor: context.data["adjustment_source_distributor_name"]) + i18n_translate("fee_calculated_on_transfer_through_entire_orders", + distributor: context.data["adjustment_source_distributor_name"]) end def tax_category_name - context.data["tax_category_name"] || context.i18n_translate("tax_category_various") + context.data["tax_category_name"] || i18n_translate("tax_category_various") end end end diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/payment_method_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/payment_method_fee.rb index 5427e52a95..d9623fe9f2 100644 --- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/payment_method_fee.rb +++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/payment_method_fee.rb @@ -6,6 +6,8 @@ module OrderManagement module EnterpriseFeeSummary module DataRepresentations class PaymentMethodFee + include WithI18n + attr_reader :context def initialize(context) @@ -13,7 +15,7 @@ module OrderManagement end def fee_type - context.i18n_translate("fee_type.payment_method") + i18n_translate("fee_type.payment_method") end def enterprise_name diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/shipping_method_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/shipping_method_fee.rb index c845dfacb8..3d7dcf56e1 100644 --- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/shipping_method_fee.rb +++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/shipping_method_fee.rb @@ -6,6 +6,8 @@ module OrderManagement module EnterpriseFeeSummary module DataRepresentations class ShippingMethodFee + include WithI18n + attr_reader :context def initialize(context) @@ -13,7 +15,7 @@ module OrderManagement end def fee_type - context.i18n_translate("fee_type.shipping_method") + i18n_translate("fee_type.shipping_method") end def enterprise_name @@ -29,7 +31,7 @@ module OrderManagement def fee_calculated_on_transfer_through_name; end def tax_category_name - context.i18n_translate("tax_category_name.shipping_instance_rate") + i18n_translate("tax_category_name.shipping_instance_rate") end end end diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/using_enterprise_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/using_enterprise_fee.rb index 7fe5d7b4e0..744cfdc862 100644 --- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/using_enterprise_fee.rb +++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/using_enterprise_fee.rb @@ -10,6 +10,8 @@ module OrderManagement module EnterpriseFeeSummary module DataRepresentations module UsingEnterpriseFee + include WithI18n + attr_reader :context def initialize(context) @@ -29,7 +31,7 @@ module OrderManagement end def fee_placement - context.i18n_translate("fee_placements.#{context.data['placement_enterprise_role']}") + i18n_translate("fee_placements.#{context.data['placement_enterprise_role']}") end end end diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/with_i18n.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/with_i18n.rb new file mode 100644 index 0000000000..8440886020 --- /dev/null +++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/with_i18n.rb @@ -0,0 +1,15 @@ +module OrderManagement + module Reports + module EnterpriseFeeSummary + module DataRepresentations + module WithI18n + private + + def i18n_translate(translation_key, options = {}) + I18n.t("order_management.reports.enterprise_fee_summary.#{translation_key}", options) + end + end + end + end + end +end diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb index 1a783c8c3b..da1e27f37a 100644 --- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb +++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb @@ -19,10 +19,6 @@ module OrderManagement data["total_amount"] end - def i18n_translate(translation_key, options = {}) - I18n.t("order_management.reports.enterprise_fee_summary.#{translation_key}", options) - end - private def representation