From f5bfe3808124da7cd2f0ab315a5ea125d3f0cbaf Mon Sep 17 00:00:00 2001 From: SomSamantray <> Date: Wed, 5 Aug 2026 19:31:28 +0530 Subject: [PATCH] fix(i18n): make future-tense block time text translatable block_short_time_in_future rendered its relative-duration text via time_ago_in_words with no :scope, falling back to Rails' bundled gem-default locale data instead of the app's own translatable config/locales files (issue #5769). Mirror the existing distance_in_words_ago pattern used by block_short_time_in_past: add a symmetric distance_in_words_in scope and point the helper at it, and drop the hardcoded literal "in " from time_in_future_title so the direction word is fully translator-controlled, like the past-tense string already is. --- app/helpers/user_blocks_helper.rb | 2 +- config/locales/en.yml | 40 ++++++++++++++++++++++++- test/helpers/user_blocks_helper_test.rb | 23 ++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/app/helpers/user_blocks_helper.rb b/app/helpers/user_blocks_helper.rb index 842cfaddd..2080eeae9 100644 --- a/app/helpers/user_blocks_helper.rb +++ b/app/helpers/user_blocks_helper.rb @@ -54,7 +54,7 @@ module UserBlocksHelper :datetime => time.xmlschema, :title => t("user_blocks.helper.short.time_in_future_title", :time_absolute => l(time, :format => :friendly), - :time_relative => time_ago_in_words(time)) + :time_relative => time_ago_in_words(time, :scope => :"datetime.distance_in_words_in")) end def block_short_time_in_past(time) diff --git a/config/locales/en.yml b/config/locales/en.yml index 4c5fd8d89..932d2c491 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -200,6 +200,44 @@ en: x_years: one: "%{count} year ago" other: "%{count} years ago" + distance_in_words_in: + about_x_hours: + one: in about %{count} hour + other: in about %{count} hours + about_x_months: + one: in about %{count} month + other: in about %{count} months + about_x_years: + one: in about %{count} year + other: in about %{count} years + almost_x_years: + one: in almost %{count} year + other: in almost %{count} years + half_a_minute: in half a minute + less_than_x_seconds: + one: in less than %{count} second + other: in less than %{count} seconds + less_than_x_minutes: + one: in less than %{count} minute + other: in less than %{count} minutes + over_x_years: + one: in over %{count} year + other: in over %{count} years + x_seconds: + one: "in %{count} second" + other: "in %{count} seconds" + x_minutes: + one: "in %{count} minute" + other: "in %{count} minutes" + x_days: + one: "in %{count} day" + other: "in %{count} days" + x_months: + one: "in %{count} month" + other: "in %{count} months" + x_years: + one: "in %{count} year" + other: "in %{count} years" printable_name: version: "v%{version}" with_name_html: "%{name} (%{id})" @@ -3501,7 +3539,7 @@ en: active: "active" active_until_read: "active until read" read_html: "read at %{time}" - time_in_future_title: "%{time_absolute}; in %{time_relative}" + time_in_future_title: "%{time_absolute}; %{time_relative}" time_in_past_title: "%{time_absolute}; %{time_relative}" show: title: "%{block_on} blocked by %{block_by}" diff --git a/test/helpers/user_blocks_helper_test.rb b/test/helpers/user_blocks_helper_test.rb index da8bdd41c..b0ba01fdf 100644 --- a/test/helpers/user_blocks_helper_test.rb +++ b/test/helpers/user_blocks_helper_test.rb @@ -73,6 +73,29 @@ class UserBlocksHelperTest < ActionView::TestCase end end + def test_block_short_time_in_future + freeze_time do + html = block_short_time_in_future(Time.now.utc + 1.hour) + assert_match(/title="[^"]*; in about 1 hour"/, html) + + html = block_short_time_in_future(Time.now.utc + 1.year) + assert_match(/title="[^"]*; in about 1 year"/, html) + + html = block_short_time_in_future(Time.now.utc + 20.seconds) + assert_match(/title="[^"]*; in less than 1 minute"/, html) + end + end + + def test_block_short_time_in_past + freeze_time do + html = block_short_time_in_past(Time.now.utc - 1.hour) + assert_match(/title="[^"]*; about 1 hour ago"/, html) + + html = block_short_time_in_past(Time.now.utc - 1.year) + assert_match(/title="[^"]*; about 1 year ago"/, html) + end + end + def test_block_duration_in_words words = block_duration_in_words(364.days) assert_equal "11 months", words -- 2.47.3