Rails distance_of_time_in_words returns “en, about_x_hours”

后端 未结 3 1290
隐瞒了意图╮
隐瞒了意图╮ 2021-02-04 17:12

I\'m having a weird problem, hoping someone knows what the issue is...

Using distance_of_time_in_words (and consequently time_ago_in_words) is not returning the actual t

3条回答
  •  暖寄归人
    2021-02-04 17:41

    That gives back a string to translate via the I18n-gem.... Try following:

    # I18n.localize(string)
    I18n.l time_ago_in_words(3.minutes.ago)
    

    And add (if doesnt exist) following in

    # config/locales/en.yml
    en:
      datetime:
        distance_in_words:
          ...
          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"
          ....
    

    And be sure to include following (maybe customized) data in your en.yml:

    http://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml

    Please tell me if it works..

提交回复
热议问题