From 56ac2e4e6199aaa1c02162fb927245343834ce44 Mon Sep 17 00:00:00 2001 From: Tsara Sudrajat Date: Fri, 21 Jan 2022 18:18:18 +0700 Subject: [PATCH] Convert product headings to load from translation --- app/models/product_import/product_importer.rb | 6 ++- config/locales/en.yml | 21 ++++++++-- spec/system/admin/product_import_spec.rb | 41 +++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb index cc8e94edf8..e33b8bbb9b 100644 --- a/app/models/product_import/product_importer.rb +++ b/app/models/product_import/product_importer.rb @@ -107,7 +107,11 @@ module ProductImport end def table_headings - @entries.first.displayable_attributes.keys.map(&:humanize) if @entries.first + return unless @entries.first + + @entries.first.displayable_attributes.keys.map do |key| + I18n.t "admin.product_import.product_headings.#{key}" + end end def products_created_count diff --git a/config/locales/en.yml b/config/locales/en.yml index a54951bdf3..2e427d730b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -200,7 +200,7 @@ en: logged_in_succesfully: "Logged in successfully" sessions: signed_out: "Signed out successfully." - already_signed_out: "Signed out successfully." + already_signed_out: "Signed out successfully." user_passwords: spree_user: updated_not_active: "Your password has been reset, but your email has not been confirmed yet." @@ -750,6 +750,21 @@ en: import_again: Upload Another File view_products: Go To Products Page view_inventory: Go To Inventory Page + product_headings: + producer: Producer + sku: SKU + name: Name + display_name: Display Name + category: Category + description: Description + units: Units + unit_type: Unit Type + variant_unit_name: Variant Unit Name + price: Price + on_hand: On Hand + on_demand: On Demand + shipping_category: Shipping Category + tax_category: Tax Category variant_overrides: loading_flash: @@ -1771,7 +1786,7 @@ en: step2: payment_method: title: Payment method - form: + form: card_number: label: Card number placeholder: e.g. 4242 4242 4242 4242 @@ -2450,7 +2465,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using new_order_cycle: "New Order Cycle" new_order_cycle_tooltip: "Open shop for a certain time period" select_a_coordinator_for_your_order_cycle: "Select a coordinator for your order cycle" - notify_producers: 'Notify producers' + notify_producers: 'Notify producers' edit_order_cycle: "Edit Order Cycle" roles: "Roles" update: "Update" diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index 5a8e62046f..350956ac74 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -565,6 +565,47 @@ describe "Product Import", js: true do expect(page).to have_no_selector 'input[type=submit][value="Save"]' end + + context 'when using other language than English' do + around do |example| + original_default_locale = I18n.default_locale + # Set the language to Spanish + I18n.default_locale = 'es' + example.run + I18n.default_locale = original_default_locale + end + + it 'returns the header in selected language' do + csv_data = CSV.generate do |csv| + csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", + "shipping_category"] + csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "1", "lb", + shipping_category_id_str] + csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "8", "oz", + shipping_category_id_str] + end + File.write('/tmp/test.csv', csv_data) + + visit main_app.admin_product_import_path + + expect(page).to have_content 'Importación de productos' + expect(page).to have_content 'Selecciona una hoja de cálculo para subir' + attach_file 'file', '/tmp/test.csv' + click_button 'Subir' + find('a.button.proceed').click + + within('.panel-header .header-caret') { find('i').click } + + within('.panel-content .table-wrap') do + product_headings = ['producer', 'category', 'units', 'unit_type', + 'price', 'on_hand', 'shipping_category', 'name'] + + product_headings.each do |heading| + expect(page).to have_content I18n.t("admin.product_import.product_headings.#{heading}").upcase + end + end + end + end end describe "when dealing with uploaded files" do