diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-12 23:42:23 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-12 23:42:23 +0200 |
| commit | cf93acb8ad44ba9cd486e8f6457d9fd9fbc041cc (patch) | |
| tree | 71ebf9abed3fe2b96262443e33da767315a5f7d2 /test/models | |
| parent | d320f8509751a886adb3ca723ebfafccaa8c191b (diff) | |
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.
Diffstat (limited to 'test/models')
| -rw-r--r-- | test/models/helpers/datetime_helper_test.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class DatetimeHelperTest < ActionView::TestCase | ||
| 4 | test "relative_time_phrase pluralizes correctly in English and German" do | ||
| 5 | travel_to Time.zone.parse("2026-07-12 12:00:00") do | ||
| 6 | I18n.with_locale(:en) do | ||
| 7 | assert_equal "1 day ago", relative_time_phrase(1.day.ago) | ||
| 8 | assert_equal "3 days ago", relative_time_phrase(3.days.ago) | ||
| 9 | end | ||
| 10 | I18n.with_locale(:de) do | ||
| 11 | assert_equal "vor 1 Tag", relative_time_phrase(1.day.ago) | ||
| 12 | assert_equal "vor 3 Tagen", relative_time_phrase(3.days.ago) | ||
| 13 | assert_equal "vor 1 Monat", relative_time_phrase(30.days.ago) | ||
| 14 | assert_equal "vor 2 Monaten", relative_time_phrase(45.days.ago) | ||
| 15 | assert_equal "vor 2 Jahren", relative_time_phrase(2.years.ago) | ||
| 16 | end | ||
| 17 | end | ||
| 18 | end | ||
| 19 | end | ||
