From 473e3f4477d4c49c9e197f12f3409244db6ccf30 Mon Sep 17 00:00:00 2001 From: neuroalien <105230050+neuroalien@users.noreply.github.com> Date: Fri, 21 Jul 2023 12:57:52 +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. 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. --- app/models/media.rb | 4 ++++ app/views/home/_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/home/_fandoms.html.erb b/app/views/home/_fandoms.html.erb index f5cd74ef2e7..8a92a8a8a2c 100644 --- a/app/views/home/_fandoms.html.erb +++ b/app/views/home/_fandoms.html.erb @@ -3,7 +3,7 @@ <% cache "homepage-fandoms-version1", skip_digest: true do %> <% Media.for_menu.each do |medium| %> <% unless medium.id.nil? %> -