From dee1453a221651598c4bfa12b88d2836a8e9e551 Mon Sep 17 00:00:00 2001 From: maebeale Date: Sat, 7 Mar 2026 06:54:33 -0500 Subject: [PATCH] Add Spanish translations for categories, sectors, category types, and workshop titles Support name_spanish on categories, sectors, and category_types so tags display translated names when viewing the workshop Spanish tab. Also adds title_spanish to workshops, shown as a heading inside the Spanish tab. Tags are now rendered inside each tab content div (English and Spanish) instead of above the tabs, so switching tabs naturally toggles the correct language. All Spanish fields fall back to English when blank. Co-Authored-By: Claude Opus 4.6 --- app/controllers/categories_controller.rb | 2 +- app/controllers/category_types_controller.rb | 2 +- app/controllers/sectors_controller.rb | 2 +- app/controllers/workshops_controller.rb | 2 +- app/decorators/category_decorator.rb | 9 +++ app/decorators/category_type_decorator.rb | 4 ++ app/decorators/workshop_decorator.rb | 2 +- app/views/categories/_form.html.erb | 7 ++ app/views/categories/_tagging_label.html.erb | 6 +- app/views/categories/show.html.erb | 4 ++ app/views/category_types/_form.html.erb | 3 + app/views/category_types/show.html.erb | 4 ++ app/views/sectors/_form.html.erb | 7 ++ app/views/sectors/_tagging_label.html.erb | 5 +- app/views/sectors/show.html.erb | 4 ++ app/views/workshops/_form.html.erb | 5 ++ app/views/workshops/_show_body.html.erb | 8 +++ app/views/workshops/_show_lazy.html.erb | 1 - app/views/workshops/_show_tags.html.erb | 15 +++-- ...sh_to_categories_sectors_category_types.rb | 7 ++ ...07143100_add_title_spanish_to_workshops.rb | 5 ++ db/schema.rb | 5 +- .../_tagging_label.html.erb_spec.rb | 21 ++++++ .../sectors/_tagging_label.html.erb_spec.rb | 19 ++++++ .../workshops/_show_body.html.erb_spec.rb | 61 +++++++++++++++++ .../workshops/_show_tags.html.erb_spec.rb | 67 +++++++++++++++++++ 26 files changed, 261 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20260307143000_add_name_spanish_to_categories_sectors_category_types.rb create mode 100644 db/migrate/20260307143100_add_title_spanish_to_workshops.rb create mode 100644 spec/views/workshops/_show_body.html.erb_spec.rb create mode 100644 spec/views/workshops/_show_tags.html.erb_spec.rb diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 7fc246c39..0b6553688 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -99,7 +99,7 @@ def set_category def category_params if params[:category] params.require(:category).permit( - :name, :category_type_id, :published, :position + :name, :name_spanish, :category_type_id, :published, :position ) else params.permit(:position) diff --git a/app/controllers/category_types_controller.rb b/app/controllers/category_types_controller.rb index cc4a3ea52..5235ab8b1 100644 --- a/app/controllers/category_types_controller.rb +++ b/app/controllers/category_types_controller.rb @@ -59,6 +59,6 @@ def set_category_type end def category_type_params - params.require(:category_type).permit(:name, :display_text, :published, :story_specific, :profile_specific) + params.require(:category_type).permit(:name, :name_spanish, :display_text, :published, :story_specific, :profile_specific) end end diff --git a/app/controllers/sectors_controller.rb b/app/controllers/sectors_controller.rb index ece19f646..e898e8953 100644 --- a/app/controllers/sectors_controller.rb +++ b/app/controllers/sectors_controller.rb @@ -75,7 +75,7 @@ def set_sector # Strong parameters def sector_params params.require(:sector).permit( - :name, :published + :name, :name_spanish, :published ) end end diff --git a/app/controllers/workshops_controller.rb b/app/controllers/workshops_controller.rb index 03ac9f226..2715d69b2 100644 --- a/app/controllers/workshops_controller.rb +++ b/app/controllers/workshops_controller.rb @@ -219,7 +219,7 @@ def log_workshop_error(action, error) def workshop_params params.require(:workshop).permit( - :title, :featured, :published, + :title, :title_spanish, :featured, :published, :full_name, :created_by_id, :windows_type_id, :workshop_idea_id, :author_credit_preference, :month, :year, :publicly_visible, diff --git a/app/decorators/category_decorator.rb b/app/decorators/category_decorator.rb index 3ddc956af..6d54e0324 100644 --- a/app/decorators/category_decorator.rb +++ b/app/decorators/category_decorator.rb @@ -3,7 +3,16 @@ def title name end + def title_spanish + name_spanish.presence || name + end + def detail(length: nil) "#{category_type.name}: #{name}" end + + def detail_spanish(length: nil) + type_label = category_type.name_spanish.presence || category_type.name + "#{type_label}: #{name_spanish.presence || name}" + end end diff --git a/app/decorators/category_type_decorator.rb b/app/decorators/category_type_decorator.rb index e49c32ec3..8c61fd79f 100644 --- a/app/decorators/category_type_decorator.rb +++ b/app/decorators/category_type_decorator.rb @@ -3,6 +3,10 @@ def title name.titleize end + def title_spanish + name_spanish.presence&.titleize || name.titleize + end + def detail(length: nil) end end diff --git a/app/decorators/workshop_decorator.rb b/app/decorators/workshop_decorator.rb index fb3a5ac10..59e7745ce 100644 --- a/app/decorators/workshop_decorator.rb +++ b/app/decorators/workshop_decorator.rb @@ -19,7 +19,7 @@ def field_has_empty_value?(field) end def has_spanish_fields? - spanish_field_values.any? + title_spanish.present? || spanish_field_values.any? end def new? diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb index 3b5f27453..13e5193ba 100644 --- a/app/views/categories/_form.html.erb +++ b/app/views/categories/_form.html.erb @@ -15,6 +15,13 @@ input_html: { class: "form-control" } %> + +
+ <%= f.input :name_spanish, + label: "Name (Spanish)", + input_html: { class: "form-control" } %> +
+
<%= f.input :category_type_id, diff --git a/app/views/categories/_tagging_label.html.erb b/app/views/categories/_tagging_label.html.erb index 10391d856..e1d83d07b 100644 --- a/app/views/categories/_tagging_label.html.erb +++ b/app/views/categories/_tagging_label.html.erb @@ -1,5 +1,7 @@ <% category ||= nil %> +<% spanish ||= false %> + <% name_only ||= false %> <% bg_color ||= DomainTheme.bg_class_for(:sectors) %> @@ -9,6 +11,8 @@ <% bg_hover_color ||= "bg-lime-200" %> <% if category %> + <% display_name = spanish ? (category.name_spanish.presence || category.name) : category.name %> + <% display_type = spanish ? (category.category_type&.name_spanish.presence || category.category_type&.name) : category.category_type&.name %> <%= link_to taggings_path(category_names_all: category.name), data: { turbo_frame: "_top", category_name: category.name, controller: "tag-link-loading", action: "click->tag-link-loading#showSpinner" }, class: "inline-flex items-center @@ -19,7 +23,7 @@ px-3 py-1 text-sm font-medium transition" do %> - <%= "#{category.category_type&.name}: " if !name_only && category.category_type %><%= category.name %> + <%= "#{display_type}: " if !name_only && display_type %><%= display_name %> <% end %> <% end %> diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb index ef78ea58b..aa6742bc3 100644 --- a/app/views/categories/show.html.erb +++ b/app/views/categories/show.html.erb @@ -19,6 +19,10 @@

Name:

<%= @category.name %>

+
+

Name (Spanish):

+

<%= @category.name_spanish.presence || "--" %>

+

Category type:

<%= @category.category_type.name %>

diff --git a/app/views/category_types/_form.html.erb b/app/views/category_types/_form.html.erb index b7a17fee8..ba8d70fd7 100644 --- a/app/views/category_types/_form.html.erb +++ b/app/views/category_types/_form.html.erb @@ -8,6 +8,9 @@ label: "Name", input_html: { class: "form-control" }, required: true %> + <%= f.input :name_spanish, + label: "Name (Spanish)", + input_html: { class: "form-control" } %> <%= f.input :display_text, label: "Display Text", hint: "For display on story idea form", diff --git a/app/views/category_types/show.html.erb b/app/views/category_types/show.html.erb index a228efaa1..06d377f64 100644 --- a/app/views/category_types/show.html.erb +++ b/app/views/category_types/show.html.erb @@ -41,6 +41,10 @@ Display text: <%= @category_type.display_text %>

+

+ Name (Spanish): + <%= @category_type.name_spanish.presence || "--" %> +

diff --git a/app/views/sectors/_form.html.erb b/app/views/sectors/_form.html.erb index 0d0ea8a23..885053f39 100644 --- a/app/views/sectors/_form.html.erb +++ b/app/views/sectors/_form.html.erb @@ -14,6 +14,13 @@ input_html: { class: "form-control" } %> + +
+ <%= f.input :name_spanish, + label: "Name (Spanish)", + input_html: { class: "form-control" } %> +
+
<%= f.input :published, as: :boolean, diff --git a/app/views/sectors/_tagging_label.html.erb b/app/views/sectors/_tagging_label.html.erb index 02c5ef7ab..f872ed308 100644 --- a/app/views/sectors/_tagging_label.html.erb +++ b/app/views/sectors/_tagging_label.html.erb @@ -1,5 +1,7 @@ <% sector ||= nil %> +<% spanish ||= false %> + <% is_leader ||= false %> <% display_leader ||= false %> @@ -11,6 +13,7 @@ <% bg_hover_color ||= "bg-lime-200" %> <% if sector %> + <% display_name = spanish ? (sector.name_spanish.presence || sector.name) : sector.name %> <%= link_to taggings_path(sector_names_all: sector.name), data: { turbo_frame: "_top", sector_name: sector.name, controller: "tag-link-loading", action: "click->tag-link-loading#showSpinner" }, class: "inline-flex items-center @@ -21,7 +24,7 @@ px-3 py-1 text-sm font-medium transition" do %> - <%= sector.name %><% if display_leader && is_leader %>(Leader)<% end %> + <%= display_name %><% if display_leader && is_leader %>(Leader)<% end %> <% end %> <% end %> diff --git a/app/views/sectors/show.html.erb b/app/views/sectors/show.html.erb index 1e99aa0dc..53abd2d2d 100644 --- a/app/views/sectors/show.html.erb +++ b/app/views/sectors/show.html.erb @@ -19,6 +19,10 @@

Name:

<%= @sector.name %>

+
+

Name (Spanish):

+

<%= @sector.name_spanish.presence || "--" %>

+

Published:

<%= @sector.published? %>

diff --git a/app/views/workshops/_form.html.erb b/app/views/workshops/_form.html.erb index e84f6f791..dbe180c2d 100644 --- a/app/views/workshops/_form.html.erb +++ b/app/views/workshops/_form.html.erb @@ -369,6 +369,11 @@