Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Translations fixes (#12928)

Damian Legawiecc2b598640724
diff --git a/admin/app/views/spree/admin/products/form/_base.html.erb b/admin/app/views/spree/admin/products/form/_base.html.erb
index fa9f9b8579..b82bfb9a87 100644
--- a/admin/app/views/spree/admin/products/form/_base.html.erb
+++ b/admin/app/views/spree/admin/products/form/_base.html.erb
@@ -8,7 +8,7 @@
<div class="form-group mb-0">
<%= f.label :description, Spree.t(:description) %>
- <div class="border rounded mb-0">
+ <div class="trix-container mb-0">
<%= f.text_area :description, { rows: 10, class: "form-control spree-rte", data: { seo_form_target: 'sourceDescriptionInput' } } %>
</div>
</div>
diff --git a/admin/app/views/spree/admin/translations/edit.html.erb b/admin/app/views/spree/admin/translations/edit.html.erb
index 5be3326b34..11d22b4195 100644
--- a/admin/app/views/spree/admin/translations/edit.html.erb
+++ b/admin/app/views/spree/admin/translations/edit.html.erb
@@ -4,7 +4,7 @@
<% end %>
<% if @locales.any?%>
<% if @locales.many? %>
- <%= form_with url: spree.edit_admin_translation_path(@resource, resource_type: @resource.class.to_s), class: "w-100 d-flex justify-content-end", data: { controller: 'auto-submit', turbo_frame: 'translations_table'}, method: :get do |f| %>
+ <%= form_with url: spree.edit_admin_translation_path(@resource, resource_type: @resource.class.to_s), class: "w-100 d-flex justify-content-end mb-3", data: { controller: 'auto-submit', turbo_frame: 'translations_table'}, method: :get do |f| %>
<div class="form-inline gap-2">
<%= f.label :translation_locale, Spree.t(:language) %>
<%= f.select :translation_locale, options_for_select(@locales.map { |locale| [Spree.t('i18n.this_file_language', locale: locale), locale] }, @selected_translation_locale), {}, { class: 'custom-select', data: { action: 'change->auto-submit#submit' } } %>
@@ -19,9 +19,9 @@
<table class="table">
<thead>
<tr>
- <th scope="col" class="w-10 text-center"><%= Spree.t(:field) %></th>
- <th scope="col" class="w-40 text-center"><%= Spree.t('i18n.this_file_language', locale: @default_locale) %> (<%= Spree.t(:default) %>)</th>
- <th scope="col" class="w-50 text-center"><%= Spree.t('i18n.this_file_language', locale: @selected_translation_locale) %></th>
+ <th scope="col" class="w-10"><%= Spree.t(:field) %></th>
+ <th scope="col" class="w-40"><%= Spree.t('i18n.this_file_language', locale: @default_locale) %> (<%= Spree.t(:default) %>)</th>
+ <th scope="col" class="w-50"><%= Spree.t('i18n.this_file_language', locale: @selected_translation_locale) %></th>
</tr>
</thead>
<tbody>
diff --git a/admin/app/views/spree/admin/translations/option_types/_form.html.erb b/admin/app/views/spree/admin/translations/option_types/_form.html.erb
index 17beb11f07..345a116e39 100644
--- a/admin/app/views/spree/admin/translations/option_types/_form.html.erb
+++ b/admin/app/views/spree/admin/translations/option_types/_form.html.erb
@@ -11,7 +11,11 @@
<%= f.fields_for :option_values do |ff| %>
<% ff.object.class.translatable_fields.each do |field| %>
- <%= render "spree/admin/translations/translation_rows/text_field_row", f: ff, field: field, locale: locale %>
+ <tr>
+ <td><%= Spree.t(field) %></td>
+ <td><%= ff.object.send(field) %></td>
+ <td><%= ff.text_field "#{field}_#{locale}", class: 'form-control' %></td>
+ </tr>
<% end %>
<% end %>
<% end %>
diff --git a/admin/app/views/spree/admin/translations/products/_form.html.erb b/admin/app/views/spree/admin/translations/products/_form.html.erb
index 2df6c04cd7..61401cd429 100644
--- a/admin/app/views/spree/admin/translations/products/_form.html.erb
+++ b/admin/app/views/spree/admin/translations/products/_form.html.erb
@@ -1,11 +1,9 @@
<%# locals: (f:, resource:, locale:) %>
<% resource.class.translatable_fields.each do |field| %>
- <% next if field == :meta_keywords %>
-
<% case field%>
<% when :description %>
- <%= render "spree/admin/translations/translation_rows/rich_textarea_row", f: f, field: field, locale: locale %>
+ <%= render "spree/admin/translations/translation_rows/tinymce_row", f: f, field: field, locale: locale %>
<% when :meta_description %>
<%= render "spree/admin/translations/translation_rows/textarea_row", f: f, field: field, locale: locale %>
<% else %>
diff --git a/admin/app/views/spree/admin/translations/translation_rows/_permalink_field_row.html.erb b/admin/app/views/spree/admin/translations/translation_rows/_permalink_field_row.html.erb
index aee5254208..3d2639336f 100644
--- a/admin/app/views/spree/admin/translations/translation_rows/_permalink_field_row.html.erb
+++ b/admin/app/views/spree/admin/translations/translation_rows/_permalink_field_row.html.erb
@@ -11,19 +11,11 @@
%>
<tr>
- <td class="text-center"><%= Spree.t(field) %></td>
+ <td><%= Spree.t(field) %></td>
<td>
- <div class="form-group">
- <div class="input-group">
- <% if base_permalink.present? %>
- <div class="input-group-prepend">
- <span class="input-group-text"><%= base_permalink %></span>
- </div>
- <% end %>
-
- <%= value %>
- </div>
- </div>
+ <code>
+ <%= f.object.permalink %>
+ </code>
</td>
<td>
<div class="form-group">
diff --git a/admin/app/views/spree/admin/translations/translation_rows/_rich_textarea_row.html.erb b/admin/app/views/spree/admin/translations/translation_rows/_rich_textarea_row.html.erb
index c6bd2075e6..8b15d1c5d0 100644
--- a/admin/app/views/spree/admin/translations/translation_rows/_rich_textarea_row.html.erb
+++ b/admin/app/views/spree/admin/translations/translation_rows/_rich_textarea_row.html.erb
@@ -1,13 +1,13 @@
<%# locals: (f:, field:, locale:) %>
<tr>
- <td class="text-center"><%= Spree.t(field) %></td>
+ <td><%= Spree.t(field) %></td>
<td class="text-wrap">
<%= @resource.send(field)%>
</td>
<td>
<div class="trix-container mb-0">
- <%= f.rich_textarea "#{field}_#{locale}" %>
+ <%= f.rich_text_area "#{field}_#{locale}" %>
</div>
</td>
</tr>
diff --git a/admin/app/views/spree/admin/translations/translation_rows/_text_field_row.html.erb b/admin/app/views/spree/admin/translations/translation_rows/_text_field_row.html.erb
index 9c233ba336..51199f1b50 100644
--- a/admin/app/views/spree/admin/translations/translation_rows/_text_field_row.html.erb
+++ b/admin/app/views/spree/admin/translations/translation_rows/_text_field_row.html.erb
@@ -1,7 +1,7 @@
<%# locals: (f:, field:, locale:) %>
<tr>
- <td class="text-center"><%= Spree.t(field) %></td>
+ <td><%= Spree.t(field) %></td>
<td><%= @resource.send(field) %></td>
<td><%= f.text_field "#{field}_#{locale}", class: 'form-control' %></td>
</tr>
diff --git a/admin/app/views/spree/admin/translations/translation_rows/_textarea_row.html.erb b/admin/app/views/spree/admin/translations/translation_rows/_textarea_row.html.erb
index d7285c7bc6..e90d32ad92 100644
--- a/admin/app/views/spree/admin/translations/translation_rows/_textarea_row.html.erb
+++ b/admin/app/views/spree/admin/translations/translation_rows/_textarea_row.html.erb
@@ -1,11 +1,11 @@
<%# locals: (f:, field:, locale:) %>
<tr>
- <td class="text-center"><%= Spree.t(field) %></td>
+ <td><%= Spree.t(field) %></td>
<td>
<%= @resource.send(field) %>
</td>
<td>
- <%= f.textarea "#{field}_#{locale}", rows: 5, class: "form-control", data: { controller: 'textarea-autogrow'} %>
+ <%= f.text_area "#{field}_#{locale}", rows: 5, class: "form-control", data: { controller: 'textarea-autogrow'} %>
</td>
</tr>
diff --git a/admin/app/views/spree/admin/translations/translation_rows/_tinymce_row.html.erb b/admin/app/views/spree/admin/translations/translation_rows/_tinymce_row.html.erb
new file mode 100644
index 0000000000..e74dc9c9c2
--- /dev/null
+++ b/admin/app/views/spree/admin/translations/translation_rows/_tinymce_row.html.erb
@@ -0,0 +1,13 @@
+<%# locals: (f:, field:, locale:) %>
+
+<tr>
+ <td><%= Spree.t(field) %></td>
+ <td>
+ <%= @resource.send(field) %>
+ </td>
+ <td>
+ <div class="trix-container">
+ <%= f.text_area "#{field}_#{locale}", rows: 10, class: "form-control spree-rte" %>
+ </div>
+ </td>
+</tr>
\ No newline at end of file
diff --git a/admin/lib/spree/admin/testing_support/capybara_utils.rb b/admin/lib/spree/admin/testing_support/capybara_utils.rb
index 2ca4e42894..924e6492f7 100644
--- a/admin/lib/spree/admin/testing_support/capybara_utils.rb
+++ b/admin/lib/spree/admin/testing_support/capybara_utils.rb
@@ -35,10 +35,6 @@ module Spree
rescue Selenium::WebDriver::Error::TimeoutError
default_options[:error].nil? ? false : raise(default_options[:error])
end
-
- def fill_in_trix_editor(id, with:)
- page.find(id, visible: :all).click.set(with)
- end
end
end
end
diff --git a/admin/spec/features/spree/admin/translations/products_spec.rb b/admin/spec/features/spree/admin/translations/products_spec.rb
new file mode 100644
index 0000000000..f9da351c47
--- /dev/null
+++ b/admin/spec/features/spree/admin/translations/products_spec.rb
@@ -0,0 +1,59 @@
+require "spec_helper"
+
+RSpec.describe "Product translations", type: :feature, js: true do
+ stub_authorization!
+
+ let(:store) { Spree::Store.default }
+
+ before do
+ allow_any_instance_of(Spree::Store).to receive(:supported_locales_list).and_return(['en', 'fr'])
+
+ I18n.backend.store_translations(:fr,
+ spree: {
+ i18n: {
+ language: 'Langue',
+ this_file_language: 'Français (FR)'
+ },
+ }
+ )
+
+ visit spree.edit_admin_product_path(product)
+
+ within('#page_actions_dropdown') do
+ click_on 'more-actions-link'
+ click_on Spree.t(:translations)
+ end
+ end
+
+ let(:product) { create(:product, name: 'product', stores: [store], meta_title: 'seo title', meta_description: 'meta description') }
+
+ it "allows to translate product" do
+ expect(page).to have_field('product_name_fr')
+
+ fill_in :product_name_fr, with: 'French product'
+ # fill_in :product_description_fr, with: 'French description'
+ fill_in :product_meta_description_fr, with: 'French meta description'
+ fill_in :product_meta_title_fr, with: 'French seo title'
+ fill_in :product_slug_fr, with: 'french-product-slug'
+
+ click_on Spree.t(:update)
+
+ expect(page).to have_content('Translations successfully saved')
+
+ I18n.with_locale(:en) do
+ expect(product.reload.name).to eq('product')
+ # expect(product.reload.description).to eq('description')
+ expect(product.reload.meta_description).to eq('meta description')
+ expect(product.reload.meta_title).to eq('seo title')
+ expect(product.reload.slug).to eq('product')
+ end
+
+ I18n.with_locale(:fr) do
+ expect(product.reload.name).to eq('French product')
+ # expect(product.reload.description).to eq('French description')
+ expect(product.reload.meta_description).to eq('French meta description')
+ expect(product.reload.meta_title).to eq('French seo title')
+ expect(product.reload.slug).to eq('french-product-slug')
+ end
+ end
+end
diff --git a/admin/spec/features/spree/admin/translations/stores_spec.rb b/admin/spec/features/spree/admin/translations/stores_spec.rb
new file mode 100644
index 0000000000..996dabbaed
--- /dev/null
+++ b/admin/spec/features/spree/admin/translations/stores_spec.rb
@@ -0,0 +1,153 @@
+require "spec_helper"
+
+RSpec.describe "Stores translations", type: :feature, js: true do
+ stub_authorization!
+
+ let(:store) do
+ create(:store,
+ name: "Store", description: "Store",
+ meta_description: "Store",
+ seo_title: "Store",
+ facebook: "https://facebook.com/store",
+ twitter: "https://x.com/store",
+ instagram: "https://instagram.com/store",
+ customer_support_email: "[email protected]",
+ address: "Store 123, 00-000 Store",
+ contact_phone: "123 456 789"
+ )
+ end
+
+ before do
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:current_store).and_return(store)
+
+ I18n.backend.store_translations(:fr,
+ spree: {
+ i18n: {
+ language: 'Langue',
+ this_file_language: 'Français (FR)'
+ },
+ }
+ )
+
+ visit spree.edit_admin_store_path(store, section: "general-settings")
+
+ within('#page_actions_dropdown') do
+ click_on 'more-actions-link'
+ click_on Spree.t(:translations)
+ end
+ end
+
+ context 'when there is only one language' do
+ it 'shows message to add more languages' do
+ expect(page).to have_content('To use translations, configure more than one locale for the store.')
+ end
+ end
+
+ context 'when there are 2 languages' do
+ let(:store) do
+ create(:store,
+ name: "Store", description: "Store",
+ meta_description: "Store",
+ seo_title: "Store",
+ facebook: "https://facebook.com/store",
+ twitter: "https://x.com/store",
+ instagram: "https://instagram.com/store",
+ customer_support_email: "[email protected]",
+ address: "Store 123, 00-000 Store",
+ contact_phone: "123 456 789",
+ supported_locales: 'en,pl'
+ )
+ end
+
+ it "allows to translate store" do
+ expect(page).to have_field('store_name_pl')
+
+ fill_in :store_name_pl, with: 'Sklep'
+ fill_in :store_meta_description_pl, with: 'Sklep'
+ fill_in :store_seo_title_pl, with: 'Sklep'
+ fill_in :store_facebook_pl, with: 'https://facebook.com/sklep'
+ fill_in :store_twitter_pl, with: 'https://x.com/sklep'
+ fill_in :store_instagram_pl, with: 'https://instagram.com/sklep'
+ fill_in :store_customer_support_email_pl, with: '[email protected]'
+ fill_in :store_address_pl, with: 'ul. Sklep 123, 00-000 Sklep'
+ fill_in :store_contact_phone_pl, with: '123 456 789'
+
+ click_on Spree.t(:update)
+
+ expect(page).to have_content('Translations successfully saved')
+
+ I18n.with_locale(:en) do
+ expect(store.reload.name).to eq('Store')
+ expect(store.meta_description).to eq('Store')
+ expect(store.seo_title).to eq('Store')
+ expect(store.facebook).to eq('https://facebook.com/store')
+ expect(store.twitter).to eq('https://x.com/store')
+ expect(store.instagram).to eq('https://instagram.com/store')
+ expect(store.customer_support_email).to eq('[email protected]')
+ expect(store.address).to eq('Store 123, 00-000 Store')
+ expect(store.contact_phone).to eq('123 456 789')
+ end
+
+ I18n.with_locale(:pl) do
+ expect(store.reload.name).to eq('Sklep')
+ expect(store.meta_description).to eq('Sklep')
+ expect(store.seo_title).to eq('Sklep')
+ expect(store.facebook).to eq('https://facebook.com/sklep')
+ expect(store.twitter).to eq('https://x.com/sklep')
+ expect(store.instagram).to eq('https://instagram.com/sklep')
+ expect(store.customer_support_email).to eq('[email protected]')
+ expect(store.address).to eq('ul. Sklep 123, 00-000 Sklep')
+ expect(store.contact_phone).to eq('123 456 789')
+ end
+ end
+ end
+
+ context 'when there are more languages' do
+ let(:store) do
+ create(:store,
+ name: "Store", description: "Store",
+ meta_description: "Store",
+ seo_title: "Store",
+ facebook: "https://facebook.com/store",
+ twitter: "https://x.com/store",
+ instagram: "https://instagram.com/store",
+ customer_support_email: "[email protected]",
+ address: "Store 123, 00-000 Store",
+ contact_phone: "123 456 789",
+ supported_locales: 'en,de,fr'
+ )
+ end
+
+ it 'shows dropdown to select language' do
+ expect(page).to have_select('translation_locale')
+ select "Français (FR)", from: 'translation_locale'
+
+ expect(page).to have_field('store_name_fr')
+
+ fill_in :store_name_fr, with: 'Magasin'
+ fill_in :store_meta_description_fr, with: 'Magasin'
+ fill_in :store_seo_title_fr, with: 'Magasin'
+ fill_in :store_facebook_fr, with: 'https://facebook.com/magasin'
+ fill_in :store_twitter_fr, with: 'https://x.com/magasin'
+ fill_in :store_instagram_fr, with: 'https://instagram.com/magasin'
+ fill_in :store_customer_support_email_fr, with: '[email protected]'
+ fill_in :store_address_fr, with: 'Magasin 123, 00-000 Magasin'
+ fill_in :store_contact_phone_fr, with: '123 456 789'
+
+ click_on Spree.t(:update)
+ expect(page).to have_content('Translations successfully saved')
+
+ I18n.with_locale(:fr) do
+ expect(store.reload.name).to eq('Magasin')
+ expect(store.meta_description).to eq('Magasin')
+ expect(store.seo_title).to eq('Magasin')
+ expect(store.facebook).to eq('https://facebook.com/magasin')
+ expect(store.twitter).to eq('https://x.com/magasin')
+ expect(store.instagram).to eq('https://instagram.com/magasin')
+ expect(store.customer_support_email).to eq('[email protected]')
+ expect(store.address).to eq('Magasin 123, 00-000 Magasin')
+ expect(store.contact_phone).to eq('123 456 789')
+ end
+ end
+ end
+end
diff --git a/admin/spec/features/spree/admin/translations/taxons_spec.rb b/admin/spec/features/spree/admin/translations/taxons_spec.rb
new file mode 100644
index 0000000000..a19b1c5606
--- /dev/null
+++ b/admin/spec/features/spree/admin/translations/taxons_spec.rb
@@ -0,0 +1,50 @@
+require "spec_helper"
+
+RSpec.describe "Taxon translations", type: :feature, js: true do
+ stub_authorization!
+
+ let(:store) { Spree::Store.default }
+
+ before do
+ allow_any_instance_of(Spree::Store).to receive(:supported_locales_list).and_return(['en', 'fr'])
+
+ I18n.backend.store_translations(:fr,
+ spree: {
+ i18n: {
+ language: 'Langue',
+ this_file_language: 'Français (FR)'
+ },
+ }
+ )
+
+ visit spree.edit_admin_taxonomy_taxon_path(taxon.taxonomy, taxon.id)
+
+ within('#page_actions_dropdown') do
+ click_on 'more-actions-link'
+ click_on Spree.t(:translations)
+ end
+ end
+
+ let(:taxonomy) { create(:taxonomy, store: store) }
+ let(:taxon) { create(:taxon, name: 'taxon') }
+
+ it "allows to translate taxon" do
+ expect(page).to have_field('taxon_name_fr')
+
+ fill_in :taxon_name_fr, with: 'French taxon'
+ fill_in_rich_text_area 'taxon_description_fr', with: 'French description'
+
+ click_on Spree.t(:update)
+
+ expect(page).to have_content('Translations successfully saved')
+
+ I18n.with_locale(:en) do
+ expect(taxon.reload.name).to eq('taxon')
+ end
+
+ I18n.with_locale(:fr) do
+ expect(taxon.reload.name).to eq('French taxon')
+ expect(taxon.reload.description.to_plain_text).to eq('French description')
+ end
+ end
+end
diff --git a/admin/spec/spec_helper.rb b/admin/spec/spec_helper.rb
index c5e69587ba..a3729a5421 100644
--- a/admin/spec/spec_helper.rb
+++ b/admin/spec/spec_helper.rb
@@ -52,6 +52,8 @@ require 'spree/testing_support/image_helpers'
require 'spree/core/controller_helpers/strong_parameters'
+require 'action_text/system_test_helper'
+
RSpec.configure do |config|
config.color = true
config.default_formatter = 'doc'
@@ -97,6 +99,8 @@ RSpec.configure do |config|
config.include Spree::Core::ControllerHelpers::StrongParameters, type: :controller
+ config.include ActionText::SystemTestHelper, type: :feature
+
config.order = :random
Kernel.srand config.seed
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 44ad6034a0..70bc8e3450 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -46,7 +46,7 @@ module Spree
'archived' => 'archived'
}.freeze
- TRANSLATABLE_FIELDS = %i[name description slug meta_description meta_keywords meta_title].freeze
+ TRANSLATABLE_FIELDS = %i[name description slug meta_description meta_title].freeze
translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)
self::Translation.class_eval do
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index f5a67fa319..9acadc03a2 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -25,8 +25,8 @@ module Spree
# Translations
#
TRANSLATABLE_FIELDS = %i[name meta_description meta_keywords seo_title facebook
- twitter instagram customer_support_email description
- address contact_phone new_order_notifications_email].freeze
+ twitter instagram customer_support_email
+ address contact_phone].freeze
translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)
self::Translation.class_eval do
acts_as_paranoid
diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rb
index 347cb4a60b..25fa5ae50b 100644
--- a/core/spec/models/spree/product_spec.rb
+++ b/core/spec/models/spree/product_spec.rb
@@ -403,7 +403,6 @@ describe Spree::Product, type: :model do
expect(product_pl_translation.description).to eq('PL description')
expect(product_pl_translation.meta_title).to eq('PL meta title')
expect(product_pl_translation.meta_description).to eq('PL meta description')
- expect(product_pl_translation.meta_keywords).to eq('PL meta keywords')
end
end
end
diff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rb
index 1ec7578a82..bdd8c3d4ed 100644
--- a/core/spec/models/spree/store_spec.rb
+++ b/core/spec/models/spree/store_spec.rb
@@ -275,7 +275,6 @@ describe Spree::Store, type: :model, without_global_store: true do
expect(store_pl_translation).to be_present
expect(store_pl_translation.name).to eq('Store PL')
- expect(store_pl_translation.description).to eq('PL description')
end
end
diff --git a/storefront/app/views/themes/default/spree/products/filters/_colors.html.erb b/storefront/app/views/themes/default/spree/products/filters/_colors.html.erb
index ce644a560f..03b170f48e 100644
--- a/storefront/app/views/themes/default/spree/products/filters/_colors.html.erb
+++ b/storefront/app/views/themes/default/spree/products/filters/_colors.html.erb
@@ -3,7 +3,7 @@
<% if filter_values.any? %>
<div class="st-accordion" data-controller='accordion' data-accordion-close-others-value="false">
<%= link_to "#colors_filter", class: "cursor-pointer uppercase flex items-center justify-between h-10 px-4 lg:px-10 text-sm tracking-widest focus:outline-none transition duration-150 ease-in-out #{'st-accordion__icon--opened' if params.dig(:filter, :options, :color).present?}", data: { action: 'accordion#toggle:prevent' } do %>
- <%= Spree.t(:colors) %>
+ <%= filter.presentation %>
<%= render 'spree/shared/icons/chevron_down' %>
<% end %>
<div class='st-accordion__content' data-accordion-id='colors_filter'>