From cf93acb8ad44ba9cd486e8f6457d9fd9fbc041cc Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 12 Jul 2026 23:42:23 +0200 Subject: Add a locale-aware relative-time helper; drop stale locale overrides Node.recently_changed and the new dashboard need "X ago" rendered correctly in both locales. Rails' own distance_of_time_in_words/ time_ago_in_words can't do this on their own -- the scope option changes which translation key is looked up, not the underlying grammar, and German's "vor" requires dative case, which is a different word form than the nominative plural Rails computes by default. relative_time_phrase/relative_distance is a small, from- scratch bucketing helper instead, with an explicit, hand-checked translation table per unit per locale. Also removes de.yml's datetime.distance_in_words and activerecord. errors blocks. Both used the old {{count}}/{{model}} interpolation syntax the current i18n gem no longer recognizes -- it silently leaves the literal placeholder text in the rendered output rather than erroring, which is why this went unnoticed until now. Both were shadowing rails-i18n's own current, correct translations for exactly these keys; deleting the local override lets the gem's version take over instead of maintaining a second, broken copy. --- test/models/helpers/datetime_helper_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/models/helpers/datetime_helper_test.rb (limited to 'test/models') diff --git a/test/models/helpers/datetime_helper_test.rb b/test/models/helpers/datetime_helper_test.rb new file mode 100644 index 0000000..a24e5d3 --- /dev/null +++ b/test/models/helpers/datetime_helper_test.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class DatetimeHelperTest < ActionView::TestCase + test "relative_time_phrase pluralizes correctly in English and German" do + travel_to Time.zone.parse("2026-07-12 12:00:00") do + I18n.with_locale(:en) do + assert_equal "1 day ago", relative_time_phrase(1.day.ago) + assert_equal "3 days ago", relative_time_phrase(3.days.ago) + end + I18n.with_locale(:de) do + assert_equal "vor 1 Tag", relative_time_phrase(1.day.ago) + assert_equal "vor 3 Tagen", relative_time_phrase(3.days.ago) + assert_equal "vor 1 Monat", relative_time_phrase(30.days.ago) + assert_equal "vor 2 Monaten", relative_time_phrase(45.days.ago) + assert_equal "vor 2 Jahren", relative_time_phrase(2.years.ago) + end + end + end +end -- cgit v1.3