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.
  • Loading branch information
neuroalien committed Jul 17, 2023
1 parent 365f1ea commit 791e8e4
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/menu/_menu_fandoms.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<% cache "menu-fandoms-version4", skip_digest: true do %>
<% Media.for_menu.each do |medium| %>
<% unless medium.id.nil? %>
<li id="medium_<%= medium.id %>"><%= link_to ts("#{medium.name}", key: 'header.fandom'), medium_fandoms_path(medium) %></li>
<li id="medium_<%= medium.id %>"><%= 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 @@ -453,7 +453,17 @@ en:
menu:
menu_fandoms:
all_fandoms: All Fandoms
anime_manga: Anime & Manga
books_literature: Books & Literature
cartoons_comics: Cartoons & Comics
media: Media
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
muted:
mute: Mute
muted_items_notice_html: You have muted some users on the Archive. Some items may not be shown, and any counts may be inaccurate. You can mute or unmute users on %{muted_users_link}.
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 = FactoryBot.create(:media, name: "Widgets; Tools & Doodads")
expect(media.translation_key).to eql("widgets_tools_doodads")
end
end
end

0 comments on commit 791e8e4

Please sign in to comment.