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 a94b64f2c1..45001595da 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -749,6 +749,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: 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