From 14544dc4dd054f807be5dd1b797d04e09f866e56 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 1 Apr 2026 10:32:47 +0200 Subject: [PATCH] Fix subject of email subscription notification e-mail being difficult to localize (#38507) --- app/mailers/email_subscription_mailer.rb | 2 +- app/views/email_subscription_mailer/notification.text.erb | 2 +- config/locales/en.yml | 8 ++++---- spec/mailers/email_subscription_mailer_spec.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/mailers/email_subscription_mailer.rb b/app/mailers/email_subscription_mailer.rb index 35bd6da2f9..318aec10d8 100644 --- a/app/mailers/email_subscription_mailer.rb +++ b/app/mailers/email_subscription_mailer.rb @@ -30,7 +30,7 @@ class EmailSubscriptionMailer < ApplicationMailer @statuses = statuses I18n.with_locale(locale) do - mail subject: default_i18n_subject(count: @statuses.size, name: @subscription.account.display_name, excerpt: @statuses.first.text.truncate(17)) + mail subject: I18n.t(@statuses.size == 1 ? 'singular' : 'plural', scope: 'email_subscription_mailer.notification.subject', name: @subscription.account.display_name, excerpt: @statuses.first.text.truncate(17)) end end diff --git a/app/views/email_subscription_mailer/notification.text.erb b/app/views/email_subscription_mailer/notification.text.erb index 7da5261b64..9e657b93f9 100644 --- a/app/views/email_subscription_mailer/notification.text.erb +++ b/app/views/email_subscription_mailer/notification.text.erb @@ -1,4 +1,4 @@ -<%= t '.title', count: @statuses.size, name: display_name(@subscription.account), excerpt: truncate(@statuses.first.text, length: 17) %> +<%= t @statuses.size == 1 ? 'singular' : 'plural', scope: 'email_subscription_mailer.notification.title', name: display_name(@subscription.account), excerpt: truncate(@statuses.first.text, length: 17) %> === diff --git a/config/locales/en.yml b/config/locales/en.yml index 76b25667df..883bf18e7a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1440,11 +1440,11 @@ en: one: Interact with this post and discover more like it. other: Interact with these posts and discover more. subject: - one: 'New post: "%{excerpt}"' - other: New posts from %{name} + plural: New posts from %{name} + singular: 'New post: "%{excerpt}"' title: - one: 'New post: "%{excerpt}"' - other: New posts from %{name} + plural: New posts from %{name} + singular: 'New post: "%{excerpt}"' email_subscriptions: active: Active confirmations: diff --git a/spec/mailers/email_subscription_mailer_spec.rb b/spec/mailers/email_subscription_mailer_spec.rb index 0d8ec6e66b..4782291145 100644 --- a/spec/mailers/email_subscription_mailer_spec.rb +++ b/spec/mailers/email_subscription_mailer_spec.rb @@ -30,7 +30,7 @@ RSpec.describe EmailSubscriptionMailer do .to send_email( to: email_subscription.email, from: 'notifications@localhost', - subject: I18n.t('email_subscription_mailer.notification.subject', count: statuses.size, name: email_subscription.account.display_name, excerpt: statuses.first.text.truncate(17)) + subject: I18n.t('email_subscription_mailer.notification.subject.singular', name: email_subscription.account.display_name, excerpt: statuses.first.text.truncate(17)) ) end end @@ -43,7 +43,7 @@ RSpec.describe EmailSubscriptionMailer do .to send_email( to: email_subscription.email, from: 'notifications@localhost', - subject: I18n.t('email_subscription_mailer.notification.subject', count: statuses.size, name: email_subscription.account.display_name, excerpt: ActionController::Base.helpers.truncate(statuses.first.text, length: 17)) + subject: I18n.t('email_subscription_mailer.notification.subject.plural', name: email_subscription.account.display_name, excerpt: ActionController::Base.helpers.truncate(statuses.first.text, length: 17)) ) end end