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.

Move translations UI to drawer component (#13155)

Damian Legawiec0bd8696bb2c5
diff --git a/admin/.claude/settings.local.json b/admin/.claude/settings.local.json
index 61ba67fcf7..bf16b08ec1 100644
--- a/admin/.claude/settings.local.json
+++ b/admin/.claude/settings.local.json
@@ -2,7 +2,11 @@
"permissions": {
"allow": [
"Bash(find:*)",
- "Bash(bundle exec rake:*)"
+ "Bash(bundle exec rake:*)",
+ "Bash(grep:*)",
+ "Bash(bundle install:*)",
+ "Bash(bundle exec rails:*)",
+ "Bash(bundle exec rspec:*)"
],
"deny": [],
"ask": []
diff --git a/admin/app/assets/stylesheets/spree/admin/components/_dialogs.scss b/admin/app/assets/stylesheets/spree/admin/components/_dialogs.scss
index 1b2f3f01f3..8d5c1cc12e 100644
--- a/admin/app/assets/stylesheets/spree/admin/components/_dialogs.scss
+++ b/admin/app/assets/stylesheets/spree/admin/components/_dialogs.scss
@@ -83,7 +83,7 @@ dialog:open {
min-width: 100vw;
}
- > turbo-frame, turbo-frame > form {
+ > turbo-frame:not(#drawer_alerts), turbo-frame > form {
display: flex;
width: 100%;
height: 100%;
diff --git a/admin/app/assets/stylesheets/spree/admin/shared/_base.scss b/admin/app/assets/stylesheets/spree/admin/shared/_base.scss
index 6549551182..292462f6b7 100644
--- a/admin/app/assets/stylesheets/spree/admin/shared/_base.scss
+++ b/admin/app/assets/stylesheets/spree/admin/shared/_base.scss
@@ -314,7 +314,7 @@ small,
}
.alerts-container {
- position: fixed;
+ position: absolute;
width: 100%;
z-index: 1070;
top: 1rem;
diff --git a/admin/app/controllers/spree/admin/translations_controller.rb b/admin/app/controllers/spree/admin/translations_controller.rb
index 96a6a86cd7..c11bfd15f1 100644
--- a/admin/app/controllers/spree/admin/translations_controller.rb
+++ b/admin/app/controllers/spree/admin/translations_controller.rb
@@ -2,21 +2,19 @@ module Spree
module Admin
class TranslationsController < Spree::Admin::BaseController
before_action :set_resource, only: [:edit, :update]
- before_action :load_data, only: [:edit]
+ before_action :load_data, only: [:edit, :update]
before_action :set_translation_locale, only: [:edit, :update]
+ helper_method :resource_class
+
def edit; end
def update
- @resource.update!(permitted_translation_params)
-
- flash[:success] = Spree.t('notice_messages.translations_saved')
-
- redirect_to spree.edit_admin_translation_path(
- @resource,
- resource_type: @resource.class.to_s,
- translation_locale: @selected_translation_locale
- )
+ if @resource.update(permitted_translation_params)
+ flash.now[:success] = flash_message_for(@resource, :successfully_updated)
+ else
+ flash.now[:error] = @resource.errors.full_messages.to_sentence
+ end
end
private
@@ -64,24 +62,6 @@ module Spree
def load_data
@locales = (current_store.supported_locales_list - [@default_locale]).sort
- @resource_name = @resource.try(:name)
-
- @back_path = case @resource.class.name
- when 'Spree::OptionType'
- spree.edit_admin_option_type_path(@resource)
- when 'Spree::Product'
- spree.edit_admin_product_path(@resource)
- when 'Spree::Property'
- spree.edit_admin_property_path(@resource)
- when 'Spree::Store'
- spree.edit_admin_store_path(section: "general-settings")
- when 'Spree::Taxon'
- spree.edit_admin_taxonomy_taxon_path(@resource.taxonomy, @resource.id)
- when 'Spree::Taxonomy'
- spree.admin_taxonomy_path(@resource)
- else
- [:edit, :admin, @resource]
- end
end
end
end
diff --git a/admin/app/helpers/spree/admin/metafields_helper.rb b/admin/app/helpers/spree/admin/metafields_helper.rb
index 453b0139ab..b98f5735bd 100644
--- a/admin/app/helpers/spree/admin/metafields_helper.rb
+++ b/admin/app/helpers/spree/admin/metafields_helper.rb
@@ -8,7 +8,7 @@ module Spree
options[:class] ||= 'dropdown-item'
options[:data] ||= { action: 'drawer#open', turbo_frame: :drawer }
- link_to_with_icon 'edit', Spree.t(:edit_metafields), spree.edit_admin_metafield_path(record, resource_type: record.class.name), options
+ link_to_with_icon 'edit', Spree.t(:metafields), spree.edit_admin_metafield_path(record, resource_type: record.class.name), options
end
def metafield_definition_resource_types
diff --git a/admin/app/helpers/spree/admin/translations_helper.rb b/admin/app/helpers/spree/admin/translations_helper.rb
index 9b64bf5a80..6444c2edf5 100644
--- a/admin/app/helpers/spree/admin/translations_helper.rb
+++ b/admin/app/helpers/spree/admin/translations_helper.rb
@@ -1,13 +1,19 @@
module Spree
module Admin
module TranslationsHelper
- def link_to_edit_translations(resource, classes: 'text-left dropdown-item')
+ def link_to_edit_translations(resource, options = {})
+ return unless Rails.application.config.spree.translatable_resources.map(&:name).include?(resource.class.name)
+ return unless can?(:update, resource)
+
+ options[:class] ||= 'dropdown-item'
+ options[:data] ||= { action: 'drawer#open', turbo_frame: :drawer }
+
link_to_with_icon(
'language',
Spree.t(:translations),
spree.edit_admin_translation_path(resource, resource_type: resource.class.to_s),
- class: classes
- ) if can?(:update, resource)
+ options
+ )
end
end
end
diff --git a/admin/app/helpers/spree/admin/turbo_helper.rb b/admin/app/helpers/spree/admin/turbo_helper.rb
index 5d1f401859..c9e5e82d14 100644
--- a/admin/app/helpers/spree/admin/turbo_helper.rb
+++ b/admin/app/helpers/spree/admin/turbo_helper.rb
@@ -23,9 +23,9 @@ module Spree
end
end
- def turbo_render_alerts
- turbo_stream.replace :alerts do
- render 'spree/admin/shared/alerts'
+ def turbo_render_alerts(frame_name = :alerts)
+ turbo_stream.replace frame_name do
+ render 'spree/admin/shared/alerts', frame_name: frame_name
end
end
diff --git a/admin/app/views/spree/admin/metafields/edit.html.erb b/admin/app/views/spree/admin/metafields/edit.html.erb
index b84ab4ffef..d53e15d3a4 100644
--- a/admin/app/views/spree/admin/metafields/edit.html.erb
+++ b/admin/app/views/spree/admin/metafields/edit.html.erb
@@ -36,7 +36,7 @@
<div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center flex-column">
<%= icon 'map-search', class: 'mb-3 opacity-50', style: 'font-size: 2rem;' %>
<p>No metafield definitions configured for <%= @resource.class.name.demodulize.titleize.pluralize %>.</p>
- <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_metafield_definition_path(resource_type: @resource.class.to_s), class: 'btn btn-primary btn-sm ml-3', data: { 'turbo-frame': '_top' } if can?(:create, Spree::MetafieldDefinition) %>
+ <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_metafield_definition_path(resource_type: @resource.class.to_s), class: 'btn btn-primary ml-3', data: { 'turbo-frame': '_top' } if can?(:create, Spree::MetafieldDefinition) %>
</div>
</div>
<% end %>
diff --git a/admin/app/views/spree/admin/metafields/update.turbo_stream.erb b/admin/app/views/spree/admin/metafields/update.turbo_stream.erb
index 950adbe67d..3f1e49cc54 100644
--- a/admin/app/views/spree/admin/metafields/update.turbo_stream.erb
+++ b/admin/app/views/spree/admin/metafields/update.turbo_stream.erb
@@ -1,2 +1 @@
-<%= turbo_hide_drawer %>
-<%= turbo_render_alerts %>
\ No newline at end of file
+<%= turbo_render_alerts :drawer_alerts %>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/option_types/edit.html.erb b/admin/app/views/spree/admin/option_types/edit.html.erb
index 244243eadf..4db67105be 100644
--- a/admin/app/views/spree/admin/option_types/edit.html.erb
+++ b/admin/app/views/spree/admin/option_types/edit.html.erb
@@ -3,9 +3,6 @@
<%= @option_type.presentation %>
<% end %>
-<% content_for :page_actions_dropdown do %>
- <%= link_to_edit_translations(@option_type) %>
-<% end %>
<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @option_type } %>
diff --git a/admin/app/views/spree/admin/policies/edit.html.erb b/admin/app/views/spree/admin/policies/edit.html.erb
index ed808fbbca..a275821684 100644
--- a/admin/app/views/spree/admin/policies/edit.html.erb
+++ b/admin/app/views/spree/admin/policies/edit.html.erb
@@ -1,5 +1,2 @@
-<% content_for :page_actions_dropdown do %>
- <%= link_to_edit_translations(@policy) %>
-<% end %>
<%= render 'spree/admin/shared/edit_resource' %>
diff --git a/admin/app/views/spree/admin/products/edit.html.erb b/admin/app/views/spree/admin/products/edit.html.erb
index 27cbc7cc9c..16c8c6cdc8 100644
--- a/admin/app/views/spree/admin/products/edit.html.erb
+++ b/admin/app/views/spree/admin/products/edit.html.erb
@@ -1,5 +1,4 @@
<% content_for :page_actions_dropdown do %>
- <%= link_to_edit_translations(@product) %>
<%= link_to_with_icon(
"files",
Spree.t(:digital_assets),
diff --git a/admin/app/views/spree/admin/properties/edit.html.erb b/admin/app/views/spree/admin/properties/edit.html.erb
index cced3d38bc..a275821684 100644
--- a/admin/app/views/spree/admin/properties/edit.html.erb
+++ b/admin/app/views/spree/admin/properties/edit.html.erb
@@ -1,5 +1,2 @@
-<% content_for :page_actions_dropdown do %>
- <%= link_to_edit_translations(@property) %>
-<% end %>
<%= render 'spree/admin/shared/edit_resource' %>
diff --git a/admin/app/views/spree/admin/shared/_alerts.html.erb b/admin/app/views/spree/admin/shared/_alerts.html.erb
index e015d146d4..8bda95605f 100644
--- a/admin/app/views/spree/admin/shared/_alerts.html.erb
+++ b/admin/app/views/spree/admin/shared/_alerts.html.erb
@@ -1,4 +1,6 @@
-<%= turbo_frame_tag :alerts do %>
+<% frame_name ||= :alerts %>
+
+<%= turbo_frame_tag frame_name do %>
<% flash.to_h.each do |msg_type, text| %>
<div class="alerts-container" style="pointer-events: none;">
<div class="d-flex justify-content-center px-2">
diff --git a/admin/app/views/spree/admin/shared/_content_header.html.erb b/admin/app/views/spree/admin/shared/_content_header.html.erb
index b7589c3897..6ff686b7b7 100644
--- a/admin/app/views/spree/admin/shared/_content_header.html.erb
+++ b/admin/app/views/spree/admin/shared/_content_header.html.erb
@@ -1,4 +1,4 @@
-<% record = @object || @customer_return || @order || @product || @vendor || @user || @admin_user || @taxon || @store_credit %>
+<% record = @object || @customer_return || @order || @product || @vendor || @user || @admin_user || @taxon || @store_credit || @store %>
<% show_record_subtitle = record && record.persisted? && record.has_attribute?(:updated_at) %>
<% content_for(:page_subtitle) do %>
@@ -30,6 +30,7 @@
<%= yield :page_actions_dropdown if content_for(:page_actions_dropdown) %>
<% if record && record.persisted? %>
<%= link_to_edit_metafields(record) %>
+ <%= link_to_edit_translations(record) %>
<% if record.respond_to?(:audits) && spree.respond_to?(:admin_audits_path) && defined?(Audited) && can?(:read, Audited.audit_class) %>
<a href="<%= spree.admin_audits_path(q: { auditable_id_eq: record.id, auditable_type_eq: record.class.to_s }) %>" target="_blank" class="dropdown-item">
diff --git a/admin/app/views/spree/admin/shared/_drawer.html.erb b/admin/app/views/spree/admin/shared/_drawer.html.erb
index fadd159824..7fd896766d 100644
--- a/admin/app/views/spree/admin/shared/_drawer.html.erb
+++ b/admin/app/views/spree/admin/shared/_drawer.html.erb
@@ -1,3 +1,4 @@
<dialog class="drawer" data-drawer-target="dialog" id="drawer-dialog">
+ <%= turbo_frame_tag :drawer_alerts %>
<%= turbo_frame_tag :drawer %>
</dialog>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/storefront/edit.html.erb b/admin/app/views/spree/admin/storefront/edit.html.erb
index d5a94b7e6e..727d490273 100644
--- a/admin/app/views/spree/admin/storefront/edit.html.erb
+++ b/admin/app/views/spree/admin/storefront/edit.html.erb
@@ -6,9 +6,6 @@
<%= Spree.t(:settings) %>
<% end %>
-<%= content_for(:page_actions_dropdown) do %>
- <%= link_to_edit_translations(@store) %>
-<% end %>
<%= content_for(:page_actions) do %>
<%= turbo_save_button_tag Spree.t('actions.update'), form: "edit_store_#{@store.id}" %>
diff --git a/admin/app/views/spree/admin/stores/form/_basic.html.erb b/admin/app/views/spree/admin/stores/form/_basic.html.erb
index 143ffa1cb2..5a54395eea 100644
--- a/admin/app/views/spree/admin/stores/form/_basic.html.erb
+++ b/admin/app/views/spree/admin/stores/form/_basic.html.erb
@@ -2,9 +2,6 @@
<%= Spree.t(:store_details) %>
<% end %>
-<%= content_for(:page_actions_dropdown) do %>
- <%= link_to_edit_translations(@store) %>
-<% end %>
<div class="card mb-4">
<div class="card-header">
diff --git a/admin/app/views/spree/admin/taxonomies/edit.html.erb b/admin/app/views/spree/admin/taxonomies/edit.html.erb
index 21bb530cf6..a275821684 100644
--- a/admin/app/views/spree/admin/taxonomies/edit.html.erb
+++ b/admin/app/views/spree/admin/taxonomies/edit.html.erb
@@ -1,5 +1,2 @@
-<% content_for :page_actions_dropdown do %>
- <%= link_to_edit_translations(@taxonomy) %>
-<% end %>
<%= render 'spree/admin/shared/edit_resource' %>
diff --git a/admin/app/views/spree/admin/taxons/edit.html.erb b/admin/app/views/spree/admin/taxons/edit.html.erb
index b8db317ffb..7310d82188 100644
--- a/admin/app/views/spree/admin/taxons/edit.html.erb
+++ b/admin/app/views/spree/admin/taxons/edit.html.erb
@@ -4,7 +4,6 @@
<% end %>
<% content_for :page_actions_dropdown do %>
- <%= link_to_edit_translations(@taxon) %>
<%= external_page_preview_link(@taxon, name: Spree.t(:taxonomy)) %>
<% end %>
diff --git a/admin/app/views/spree/admin/translations/_translations_unavailable.html.erb b/admin/app/views/spree/admin/translations/_translations_unavailable.html.erb
deleted file mode 100644
index 2b6cd14585..0000000000
--- a/admin/app/views/spree/admin/translations/_translations_unavailable.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<div class="card">
- <div class="card-body">
- <p>To use translations, configure more than one locale for the store.</p>
- <% if can?(:edit, current_store) %>
- <%= link_to_with_icon 'settings', 'Configure store', spree.edit_admin_store_path(section: 'general-settings'), class: 'btn btn-light' %>
- <% end %>
- </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 8b1c9dbcc8..71e353a87f 100644
--- a/admin/app/views/spree/admin/translations/edit.html.erb
+++ b/admin/app/views/spree/admin/translations/edit.html.erb
@@ -1,57 +1,38 @@
-<% content_for :page_title do %>
- <%= page_header_back_button @back_path %>
- <span class="mr-3"><%= Spree.t(:translations_for, resource_name: @resource.try(:name)) %></span>
-<% 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 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' } } %>
+<%= turbo_frame_tag :drawer do %>
+ <%= drawer_header(Spree.t(:translations)) %>
+ <% if @locales.any? %>
+ <%= form_for @resource, url: spree.admin_translation_path(@resource, resource_type: resource_class.to_s), method: :put do |f| %>
+ <div class="drawer-body">
+ <ul class="nav nav-pills mb-3">
+ <% @locales.each do |locale| %>
+ <%= nav_item(
+ Spree.t('i18n.this_file_language', locale: locale),
+ spree.edit_admin_translation_path(@resource, resource_type: resource_class.to_s, translation_locale: locale),
+ active: (locale == @selected_translation_locale)
+ ) %>
+ <% end %>
+ </ul>
+
+ <%= hidden_field_tag :translation_locale, @selected_translation_locale %>
+ <% options = { f: f, resource: @resource, locale: @selected_translation_locale } %>
+
+ <%= render "spree/admin/translations/#{resource_class.name.demodulize.underscore.pluralize}/form", options %>
+ </div>
+ <div class="drawer-footer">
+ <%= turbo_save_button_tag %>
+ <%= drawer_discard_button %>
</div>
<% end %>
- <% end %>
- <%= form_with model: @resource, url: spree.admin_translation_path(@resource, resource_type: @resource.class.to_s), method: :put, class: 'form-horizontal' do |f| %>
- <div class="card mb-4">
- <div class="card-body p-0">
- <%= turbo_frame_tag :translations_table, refresh: "morph" do %>
- <%= hidden_field_tag :translation_locale, @selected_translation_locale %>
- <table class="table">
- <thead>
- <tr>
- <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>
- <% options = { f: f, resource: @resource, locale: @selected_translation_locale } %>
- <% case @resource.class.name %>
- <% when 'Spree::OptionType' %>
- <%= render 'spree/admin/translations/option_types/form', options %>
- <% when 'Spree::Product' %>
- <%= render 'spree/admin/translations/products/form', options %>
- <% when 'Spree::Property' %>
- <%= render 'spree/admin/translations/properties/form', options %>
- <% when 'Spree::Store' %>
- <%= render 'spree/admin/translations/stores/form', options %>
- <% when 'Spree::Taxon' %>
- <%= render 'spree/admin/translations/taxons/form', options %>
- <% when 'Spree::Taxonomy' %>
- <%= render 'spree/admin/translations/taxonomies/form', options %>
- <% when 'Spree::Policy' %>
- <%= render 'spree/admin/translations/policies/form', options %>
- <% end %>
- </tbody>
- </table>
+ <% else %>
+ <div class="drawer-body">
+ <div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center flex-column">
+ <%= icon 'language', class: 'mb-3 opacity-50', style: 'font-size: 2rem;' %>
+ <p class="text-center"><%= Spree.t('admin.translations.no_translations_configured') %></p>
+
+ <% if can?(:edit, current_store) %>
+ <%= link_to_with_icon 'settings', Spree.t('admin.translations.configure_store'), spree.edit_admin_store_path(section: 'general-settings'), class: 'btn btn-primary', data: { 'turbo-frame': '_top' } %>
<% end %>
</div>
</div>
- <div class="form-actions d-flex justify-content-between">
- <%= turbo_save_button_tag Spree.t('actions.update') %>
- <%= link_to Spree.t('actions.discard'), @back_path, class: 'btn btn-light', data: { turbo_frame: '_top' } %>
- </div>
<% end %>
-<% else %>
- <%= render partial: 'spree/admin/translations/translations_unavailable' %>
-<% end %>
+<% end %>
\ No newline at end of file
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 61401cd429..5fc75ee61b 100644
--- a/admin/app/views/spree/admin/translations/products/_form.html.erb
+++ b/admin/app/views/spree/admin/translations/products/_form.html.erb
@@ -10,3 +10,5 @@
<%= render "spree/admin/translations/translation_rows/text_field_row", f: f, field: field, locale: locale %>
<% end %>
<% end %>
+
+<div class="pb-5"></div>
\ No newline at end of file
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 3d2639336f..adf3c0552c 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
@@ -10,24 +10,15 @@
translated_value = f.object.send("#{field}_#{locale}")&.delete_prefix(base_permalink_translated)
%>
-<tr>
- <td><%= Spree.t(field) %></td>
- <td>
- <code>
- <%= f.object.permalink %>
- </code>
- </td>
- <td>
- <div class="form-group">
- <div class="input-group">
- <% if base_permalink_translated.present? %>
- <div class="input-group-prepend">
- <span class="input-group-text"><%= base_permalink_translated %></span>
- </div>
- <% end %>
-
- <%= f.text_field "#{field}_#{locale}", value: translated_value, class: 'form-control' %>
+<div class="form-group">
+ <%= f.label field, Spree.t(field) %>
+ <div class="input-group">
+ <% if base_permalink_translated.present? %>
+ <div class="input-group-prepend">
+ <span class="input-group-text"><%= base_permalink_translated %></span>
</div>
- </div>
- </td>
-</tr>
+ <% end %>
+
+ <%= f.text_field "#{field}_#{locale}", value: translated_value, class: 'form-control' %>
+ </div>
+</div>
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 8b15d1c5d0..6a741602ba 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,3 @@
<%# locals: (f:, field:, locale:) %>
-<tr>
- <td><%= Spree.t(field) %></td>
- <td class="text-wrap">
- <%= @resource.send(field)%>
- </td>
- <td>
- <div class="trix-container mb-0">
- <%= f.rich_text_area "#{field}_#{locale}" %>
- </div>
- </td>
-</tr>
+<%= f.spree_rich_text_area "#{field}_#{locale}", label: Spree.t(field) %>
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 51199f1b50..b914d429ec 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,3 @@
<%# locals: (f:, field:, locale:) %>
-<tr>
- <td><%= Spree.t(field) %></td>
- <td><%= @resource.send(field) %></td>
- <td><%= f.text_field "#{field}_#{locale}", class: 'form-control' %></td>
-</tr>
+<%= f.spree_text_field "#{field}_#{locale}", label: Spree.t(field) %>
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 e90d32ad92..0a4166b8fe 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,4 @@
<%# locals: (f:, field:, locale:) %>
-<tr>
- <td><%= Spree.t(field) %></td>
- <td>
- <%= @resource.send(field) %>
- </td>
- <td>
- <%= f.text_area "#{field}_#{locale}", rows: 5, class: "form-control", data: { controller: 'textarea-autogrow'} %>
- </td>
-</tr>
+
+<%= f.spree_text_area "#{field}_#{locale}", label: Spree.t(field) %>
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
index e74dc9c9c2..cb8a763a2d 100644
--- 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
@@ -1,13 +1,6 @@
<%# 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
+<%= f.label field, Spree.t(field) %>
+<div class="trix-container">
+ <%= f.text_area "#{field}_#{locale}", class: "spree-rte" %>
+</div>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/translations/update.turbo_stream.erb b/admin/app/views/spree/admin/translations/update.turbo_stream.erb
new file mode 100644
index 0000000000..3f1e49cc54
--- /dev/null
+++ b/admin/app/views/spree/admin/translations/update.turbo_stream.erb
@@ -0,0 +1 @@
+<%= turbo_render_alerts :drawer_alerts %>
\ No newline at end of file
diff --git a/admin/config/locales/en.yml b/admin/config/locales/en.yml
index 71c07633cc..6742ed1bd0 100644
--- a/admin/config/locales/en.yml
+++ b/admin/config/locales/en.yml
@@ -260,6 +260,9 @@ en:
automatic_info: Automatically add products to this taxon if they match the rules you set.
manual: Manual
manual_info: Curate products manually. You can add or remove them in bulk.
+ translations:
+ configure_store: Configure store
+ no_translations_configured: No translations configured. Please configure more than one locale for the store to use translations.
upload_new_asset: Upload new asset
user:
last_order_placed: Last order placed
diff --git a/admin/spec/controllers/spree/admin/translations_controller_spec.rb b/admin/spec/controllers/spree/admin/translations_controller_spec.rb
new file mode 100644
index 0000000000..0e8180ab08
--- /dev/null
+++ b/admin/spec/controllers/spree/admin/translations_controller_spec.rb
@@ -0,0 +1,89 @@
+require 'spec_helper'
+
+RSpec.describe Spree::Admin::TranslationsController, type: :controller do
+ stub_authorization!
+ render_views
+
+ let(:product) { create(:product, name: 'Original Name') }
+ let(:resource_type) { 'Spree::Product' }
+ let(:translation_locale) { 'fr' }
+ let(:translated_name) { 'Nom Français' }
+
+ before do
+ allow_any_instance_of(Spree::Store).to receive(:supported_locales_list).and_return(['en', 'fr'])
+ allow(controller).to receive(:current_store).and_return(Spree::Store.default)
+ end
+
+ describe 'GET #edit' do
+ it 'assigns @resource and renders the edit template' do
+ get :edit, params: { resource_type: resource_type, id: product.slug, translation_locale: translation_locale }
+ expect(response).to render_template(:edit)
+ expect(assigns(:resource)).to eq(product)
+ expect(assigns(:locales)).to include('fr')
+ expect(assigns(:locales)).not_to include('en')
+ end
+
+ context 'when resource_type is missing' do
+ it 'raises ActiveRecord::RecordNotFound' do
+ expect {
+ get :edit, params: { id: product.slug, resource_type: '', translation_locale: translation_locale }
+ }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
+ context 'when resource_type is invalid' do
+ it 'raises ActiveRecord::RecordNotFound' do
+ expect {
+ get :edit, params: { resource_type: 'InvalidType', id: product.slug, translation_locale: translation_locale }
+ }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+
+ describe 'PUT #update' do
+ let(:product_params) do
+ {
+ "name_#{translation_locale}" => translated_name
+ }
+ end
+
+ it 'updates the translation and sets flash success' do
+ put :update, format: :turbo_stream, params: {
+ resource_type: resource_type,
+ id: product.slug,
+ translation_locale: translation_locale,
+ product: product_params
+ }
+ expect(response).to have_http_status(:ok)
+ expect(flash.now[:success]).to be_present
+ product.reload
+ expect(product.send("name_#{translation_locale}")).to eq(translated_name)
+ end
+
+ context 'when resource_type is missing' do
+ it 'raises ActiveRecord::RecordNotFound' do
+ expect {
+ put :update, format: :turbo_stream, params: {
+ id: product.slug,
+ resource_type: '',
+ translation_locale: translation_locale,
+ product: product_params
+ }
+ }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
+ context 'when resource_type is invalid' do
+ it 'raises ActiveRecord::RecordNotFound' do
+ expect {
+ put :update, format: :turbo_stream, params: {
+ resource_type: 'InvalidType',
+ id: product.slug,
+ translation_locale: translation_locale,
+ product: product_params
+ }
+ }.to raise_error(ActiveRecord::RecordNotFound)
+ 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
deleted file mode 100644
index f9da351c47..0000000000
--- a/admin/spec/features/spree/admin/translations/products_spec.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-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
deleted file mode 100644
index 996dabbaed..0000000000
--- a/admin/spec/features/spree/admin/translations/stores_spec.rb
+++ /dev/null
@@ -1,153 +0,0 @@
-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
deleted file mode 100644
index a19b1c5606..0000000000
--- a/admin/spec/features/spree/admin/translations/taxons_spec.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-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/core/config/locales/en.yml b/core/config/locales/en.yml
index f663971ae6..6264aa0695 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -972,7 +972,6 @@ en:
duplicating: Duplicating
edit: Edit
edit_address: Edit address
- edit_metafields: Edit Metafields
edit_refund: Edit refund
editing_resource: Editing %{resource}
editing_rma_reason: Editing RMA Reason