Skip to content

Commit

Permalink
AO3-6553 Bonus i18n for media on homepage
Browse files Browse the repository at this point in the history
This is not strictly related to the a11y issue, but we're trying to add
i18n if we can when we touch a file.

The presence of `ts` in the original shows that we always intended to
translate media names. We don't usually translate tags, but the media
tags are a special case, because they're heavily used in site navigation

The locale preference is not transmitted at the moment, so we don't risk
caching the navigation in a non-English language for the entire site.

When we know what the parameters or settings look like, we should be
able to do something like add the locale key to the cache key, to have
one cache per locale.
  • Loading branch information
neuroalien committed Jul 24, 2023
1 parent 2d19c4e commit 473e3f4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def child_types
['Fandom']
end

def translation_key
name.parameterize(separator: "_")
end

# The media tag for unwrangled fandoms
def self.uncategorized
tag = self.find_or_create_by_name(ArchiveConfig.MEDIA_UNCATEGORIZED_NAME)
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/_fandoms.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<% cache "homepage-fandoms-version1", skip_digest: true do %>
<% Media.for_menu.each do |medium| %>
<% unless medium.id.nil? %>
<li><%= link_to ts("#{medium.name}"), medium_fandoms_path(medium) %></li>
<li><%= link_to t(".#{medium.translation_key}"), medium_fandoms_path(medium) %></li>
<% end %>
<% end %>
<% end %>
Expand Down
10 changes: 10 additions & 0 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,16 @@ en:
page_title: Donate or Volunteer
fandoms:
all_fandoms: All Fandoms
anime_manga: Anime & Manga
books_literature: Books & Literature
cartoons_comics: Cartoons & Comics
movies: Movies
music_bands: Music & Bands
other_media: Other Media
real_people_celebrities: Real People & Celebrities
tv_shows: TV Shows
uncategorized_fandoms: Uncategorized Fandoms
video_games: Video Games
index:
browse_or_favorite: Browse fandoms by media or favorite up to %{count} tags to have them listed here!
find_your_favorites: Find your favorites
Expand Down
10 changes: 10 additions & 0 deletions spec/models/media_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "spec_helper"

describe Media do
describe "#translation_key" do
it "returns a parameterized version of the media name using underscore as a separator" do
media = create(:media, name: "Widgets; Tools & Doodads")
expect(media.translation_key).to eql("widgets_tools_doodads")
end
end
end

0 comments on commit 473e3f4

Please sign in to comment.