Skip to content

Commit 14d40f5

Browse files
authored
Merge pull request #3329 from projectblacklight/translation-subheading
Extract Translations::SubheadingComponent
2 parents 07fb5d8 + ea3dbbf commit 14d40f5

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h2 class='translation-subheading mt-4'>
2+
<%= text %>
3+
</h2>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module Spotlight
4+
module Translations
5+
# Draws a sub-heading for a translation.
6+
class SubheadingComponent < ViewComponent::Base
7+
def initialize(key:)
8+
@key = key
9+
super
10+
end
11+
12+
def text
13+
t(@key, scope: 'spotlight.translations')
14+
end
15+
end
16+
end
17+
end

app/views/spotlight/translations/_general.html.erb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
<%= hidden_field_tag :language, @language %>
55
66
<div class='translation-basic-settings'>
7-
<h2 class='translation-subheading'>
8-
<%= t('.basic_settings.label') %>
9-
</h2>
7+
<%= render Spotlight::Translations::SubheadingComponent.new(key: 'general.basic_settings.label') %>
108
119
<% translation = Translation.find_or_initialize_by(exhibit: current_exhibit, key: "#{current_exhibit.slug}.title", locale: @language) %>
1210
<%= f.fields_for :translations, translation do |translation_fields| %>
@@ -73,9 +71,7 @@
7371
<% end %>
7472
</div>
7573
<div class='translation-main-menu'>
76-
<h2 class='translation-subheading'>
77-
<%= t('.main_menu.label') %>
78-
</h2>
74+
<%= render Spotlight::Translations::SubheadingComponent.new(key: 'general.main_menu.label') %>
7975
8076
<% translation = Translation.find_or_initialize_by(exhibit: current_exhibit, key: "spotlight.curation.nav.home", locale: @language) %>
8177
<%= f.fields_for :translations, translation do |translation_fields| %>

app/views/spotlight/translations/_metadata.html.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
3232
<% if current_exhibit.custom_fields.any? %>
3333
<div class='translation-exhibit-specific-fields'>
34-
<h2 class='translation-subheading'>
35-
<%= t('.exhibit_specific_fields.label') %>
36-
</h2>
34+
<%= render Spotlight::Translations::SubheadingComponent.new(key: 'metadata.exhibit_specific_fields.label') %>
3735
3836
<% current_exhibit.custom_fields.each do |custom_field| %>
3937
<% translation = Translation.find_or_initialize_by(exhibit: current_exhibit, key: "blacklight.search.fields.#{custom_field.field}", locale: @language) %>

app/views/spotlight/translations/_pages.html.erb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,22 @@
33

44
<%= bootstrap_form_for @exhibit, url: polymorphic_path([:update_all, @exhibit, :pages]), layout: :horizontal, control_col: 'col-sm-10', html: {:'data-form-observer' => true} do |f| %>
55
<div class="translation-home-page-settings">
6-
<h2 class="translation-subheading">
7-
<%= t('.home_page.label') %>
8-
</h2>
6+
<%= render Spotlight::Translations::SubheadingComponent.new(key: 'pages.home_page.label') %>
7+
98
<%= render 'pages_table', pages: [current_exhibit.home_page], f: f %>
109
</div>
1110

1211
<% if current_exhibit.feature_pages.any? %>
1312
<div class="translation-feature-page-settings">
14-
<h2 class="translation-subheading">
15-
<%= t('.feature_pages.label') %>
16-
</h2>
13+
<%= render Spotlight::Translations::SubheadingComponent.new(key: 'pages.feature_pages.label') %>
1714

1815
<%= render 'pages_table', pages: current_exhibit.feature_pages.for_default_locale, f: f %>
1916
</div>
2017
<% end %>
2118

2219
<% if current_exhibit.about_pages.any? %>
2320
<div class="translation-about-page-settings">
24-
<h2 class="translation-subheading">
25-
<%= t('.about_pages.label') %>
26-
</h2>
21+
<%= render Spotlight::Translations::SubheadingComponent.new(key: 'pages.about_pages.label') %>
2722

2823
<%= render 'pages_table', pages: current_exhibit.about_pages.for_default_locale, f: f %>
2924
</div>

app/views/spotlight/translations/_search_fields.html.erb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
<%= hidden_field_tag :tab, 'search_fields', id: nil %>
66
77
<div class='translation-field-based-search-fields'>
8-
<h2 class='translation-subheading'>
9-
<%= t('.field_based_search_fields.label') %>
10-
</h2>
8+
<%= render Spotlight::Translations::SubheadingComponent.new(key: 'search_fields.field_based_search_fields.label') %>
119
1210
<% current_exhibit.blacklight_config.search_fields.select { |_, config| config.if }.each do |key, search_config| %>
1311
<% translation = Translation.find_or_initialize_by(exhibit: current_exhibit, key: "blacklight.search.fields.search.#{key}", locale: @language) %>
@@ -35,9 +33,7 @@
3533
</div>
3634
3735
<div class='translation-facet-fields'>
38-
<h2 class='translation-subheading'>
39-
<%= t('.facet_fields.label') %>
40-
</h2>
36+
<%= render Spotlight::Translations::SubheadingComponent.new(key: 'search_fields.facet_fields.label') %>
4137
4238
<% current_exhibit.blacklight_config.facet_fields.each do |key, facet_config| %>
4339
<% translation = Translation.find_or_initialize_by(exhibit: current_exhibit, key: "blacklight.search.fields.facet.#{key}", locale: @language) %>
@@ -65,9 +61,7 @@
6561
</div>
6662
6763
<div class='translation-sort-fields'>
68-
<h2 class='translation-subheading'>
69-
<%= t('.sort_fields.label') %>
70-
</h2>
64+
<%= render Spotlight::Translations::SubheadingComponent.new(key: 'search_fields.sort_fields.label') %>
7165
7266
<% current_exhibit.blacklight_config.sort_fields.each do |key, sort_config| %>
7367
<% translation = Translation.find_or_initialize_by(exhibit: current_exhibit, key: "blacklight.search.fields.sort.#{key}", locale: @language) %>

0 commit comments

Comments
 (0)