Fellow Stranger
Fellow Stranger

Reputation: 34023

Customize I18n for time_ago_in_words

I use time_ago_in_words for both future timestamps and past.

This is how my en.yml looks like:

datetime:
  distance_in_words:
    x_days:
      one:   "1 day"
      other: "%{count} days"

I want to print out "yesterday" instead of "1 day" if the timestamp isn't future.

Is this possible at all?

Upvotes: 0

Views: 1038

Answers (1)

Leonel Galán
Leonel Galán

Reputation: 7167

Short answer is NO, time_ago_in_words simply call distance_of_time_in_words setting the to_time param to Time.now.

Edit: For the sake of readability.

Long answer (discussed in comments): It's possible to use distance_of_time_in_words setting the :scope option to use your translations rather than the default ones. Still, tomorrow and yesterday are "1 day" from now, so it's necessary to wrap it on a custom method that treats past and future dates differently.

Upvotes: 1

Related Questions