Skip to content

Commit

Permalink
Use i18n for text differences between viewer types
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jan 31, 2025
1 parent 87e41e4 commit 662975b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/components/companion_windows_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<% if render_content_list_panel? %>
<section id="object-content" role="tabpanel">
<%= render ContentListComponent.new(viewer:, heading: viewer.content_heading) %>
<%= render ContentListComponent.new(viewer:) %>
</section>
<% end %>

Expand Down
9 changes: 6 additions & 3 deletions app/components/content_list_component.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# frozen_string_literal: true

class ContentListComponent < ViewComponent::Base
def initialize(viewer:, heading:)
def initialize(viewer:)
@viewer = viewer
@heading = heading
end

attr_reader :viewer, :heading
attr_reader :viewer

def heading
t('content_list_heading', scope: viewer.i18n_path)
end
end
6 changes: 5 additions & 1 deletion app/viewers/embed/viewer/common_viewer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ def display_header?
!embed_request.hide_title?
end

def i18n_path
"viewers.#{self.class.name.demodulize.underscore}"
end

def iframe_title
I18n.t("viewers.#{self.class.name.demodulize.underscore}.title", default: 'Viewer')
I18n.t('title', default: 'Viewer', scope: i18n_path)
end

private
Expand Down
5 changes: 0 additions & 5 deletions app/viewers/embed/viewer/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ def importmap
'media'
end

# The heading shown in the Content List of the CompanionWindowComponent
def content_heading
'Media content'
end

private

def default_height
Expand Down
5 changes: 0 additions & 5 deletions app/viewers/embed/viewer/pdf_viewer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ def available?
document_resource_files.first&.downloadable?
end

# The heading shown in the Content List of the CompanionWindowComponent
def content_heading
'Contents'
end

private

def document_resource_files
Expand Down
1 change: 1 addition & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# and recreated between test runs. Don't rely on the data there!

Rails.application.configure do
config.i18n.raise_on_missing_translations = true
# Settings specified here will take precedence over those in config/application.rb.

# While tests run files are not watched, reloading is not necessary.
Expand Down
30 changes: 16 additions & 14 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,35 @@

en:
restrictions:
not_accessible: 'This item cannot be accessed online. See Access conditions for more information.'
logged_in: 'Logged in.'
not_accessible: "This item cannot be accessed online. See Access conditions for more information."
logged_in: "Logged in."
date:
formats:
sul: '%d-%b-%Y'
sul_was_long: '%d %B %Y'
sul: "%d-%b-%Y"
sul_was_long: "%d %B %Y"
number:
human:
storage_units:
units:
kb: kB # This is the SI unit for 10^3
viewers:
file:
title: 'File viewer'
title: "File viewer"
geo:
title: 'Geospatial viewer'
title: "Geospatial viewer"
m3_viewer:
title: 'Image viewer'
title: "Image viewer"
media:
title: 'Media viewer'
title: "Media viewer"
content_list_heading: Media content
pdf_viewer:
title: 'PDF viewer'
title: "PDF viewer"
content_list_heading: Contents
model_viewer:
title: '3-D object viewer'
title: "3-D object viewer"
was_seed:
title: 'File viewer'
title: "File viewer"
download_files:
zero: 'No file available for download'
one: '1 file available for download'
other: '%{count} files available for download'
zero: "No file available for download"
one: "1 file available for download"
other: "%{count} files available for download"

0 comments on commit 662975b

Please sign in to comment.