Rails time_ago_in_words выдает плохой вывод - PullRequest
1 голос
/ 07 января 2011

Я думал, что это может быть связано с переходом на activesupport 2.3.5, но теперь я верю, что должно было произойти что-то еще.

Модель имеет действительную дату стиля rfc822:

>> s.lastVisitDate
=> "Thu, 06 Jan 2011 22:24:10 -0800"

Но, на мой взгляд:

<%=h time_ago_in_words(@site.lastVisitDate) -%>

renders: *about {{count}} hours ago* 
instead of: *about 2 hours ago* which was working just fine earlier.

Интересно, видел ли кто-нибудь еще такое поведение? Я просмотрел историю версий для модели и вида, и в последнее время ничего не изменилось, поэтому я считаю, что, должно быть, что-то напутало на стороне конфигурации.

1 Ответ

0 голосов
/ 07 января 2011

Я обнаружил, что пропустил соответствующие значения в файле локали.

Поэтому в моем случае я добавил следующее в /config/locales/en.yml

Я не уверенпочему это раньше работало или какие конкретные изменения в gem или config вызвали эту проблему, но правильное определение здесь делает actionpack счастливым.

# Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
  datetime:
    distance_in_words:
      half_a_minute: "half a minute"
      less_than_x_seconds:
        one:   "less than 1 second"
        other: "less than %{count} seconds"
      x_seconds:
        one:   "1 second"
        other: "%{count} seconds"
      less_than_x_minutes:
        one:   "less than a minute"
        other: "less than %{count} minutes"
      x_minutes:
        one:   "1 minute"
        other: "%{count} minutes"
      about_x_hours:
        one:   "about 1 hour"
        other: "about %{count} hours"
      x_days:
        one:   "1 day"
        other: "%{count} days"
      about_x_months:
        one:   "about 1 month"
        other: "about %{count} months"
      x_months:
        one:   "1 month"
        other: "%{count} months"
      about_x_years:
        one:   "about 1 year"
        other: "about %{count} years"
      over_x_years:
        one:   "over 1 year"
        other: "over %{count} years"
      almost_x_years:
        one:   "almost 1 year"
        other: "almost %{count} years"
    prompts:
      year:   "Year"
      month:  "Month"
      day:    "Day"
      hour:   "Hour"
      minute: "Minute"
      second: "Seconds"
...