From 791e8e4b913c8f4d101e08c76e17076788d12818 Mon Sep 17 00:00:00 2001 From: neuroalien <105230050+neuroalien@users.noreply.github.com> Date: Tue, 4 Jul 2023 22:38:14 +0100 Subject: [PATCH] AO3-6553 Bonus i18n for media on homepage This is not strictly related to the a11y issue, but we're trying to add i18n if we can when we touch a file. --- app/models/media.rb | 4 ++++ app/views/menu/_menu_fandoms.html.erb | 2 +- config/locales/views/en.yml | 10 ++++++++++ spec/models/media_spec.rb | 10 ++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 spec/models/media_spec.rb diff --git a/app/models/media.rb b/app/models/media.rb index 5aa0081185b..851fcb1bdf0 100644 --- a/app/models/media.rb +++ b/app/models/media.rb @@ -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) diff --git a/app/views/menu/_menu_fandoms.html.erb b/app/views/menu/_menu_fandoms.html.erb index bf14f51228f..685a2732120 100644 --- a/app/views/menu/_menu_fandoms.html.erb +++ b/app/views/menu/_menu_fandoms.html.erb @@ -4,7 +4,7 @@ <% cache "menu-fandoms-version4", skip_digest: true do %> <% Media.for_menu.each do |medium| %> <% unless medium.id.nil? %> -
  • <%= link_to ts("#{medium.name}", key: 'header.fandom'), medium_fandoms_path(medium) %>
  • +
  • <%= link_to t(".#{medium.translation_key}"), medium_fandoms_path(medium) %>
  • <% end %> <% end %> <% end %> diff --git a/config/locales/views/en.yml b/config/locales/views/en.yml index 8aed6f929f5..60fa5b06fad 100644 --- a/config/locales/views/en.yml +++ b/config/locales/views/en.yml @@ -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}. diff --git a/spec/models/media_spec.rb b/spec/models/media_spec.rb new file mode 100644 index 00000000000..2363bc75906 --- /dev/null +++ b/spec/models/media_spec.rb @@ -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