diff options
author | Zachary Scott <mail@zzak.io> | 2015-06-18 17:28:38 -0400 |
---|---|---|
committer | Zachary Scott <mail@zzak.io> | 2015-06-18 17:28:38 -0400 |
commit | dd1ac541578cd9a32748980fae2880b9d5ed72b9 (patch) | |
tree | beb6c580f4a0a3286f82cfef87d28c70c2f341ee /actionview/lib/action_view/helpers | |
parent | 8e9f57f6cd23ae4c092a9bcd608c7a5e56204dd3 (diff) | |
parent | f6d325eda4f162a4f48d0bed02b1ce0e68096d6a (diff) | |
download | rails-dd1ac541578cd9a32748980fae2880b9d5ed72b9.tar.gz rails-dd1ac541578cd9a32748980fae2880b9d5ed72b9.tar.bz2 rails-dd1ac541578cd9a32748980fae2880b9d5ed72b9.zip |
Merge pull request #20549 from maurogeorge/distance_of_time_in_words-rdoc
Add RDoc about scope option on distance_of_time_in_words
Diffstat (limited to 'actionview/lib/action_view/helpers')
-rw-r--r-- | actionview/lib/action_view/helpers/date_helper.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/actionview/lib/action_view/helpers/date_helper.rb b/actionview/lib/action_view/helpers/date_helper.rb index 394e20ff2b..813eda08a3 100644 --- a/actionview/lib/action_view/helpers/date_helper.rb +++ b/actionview/lib/action_view/helpers/date_helper.rb @@ -68,6 +68,26 @@ module ActionView # distance_of_time_in_words(from_time, to_time, include_seconds: true) # => about 6 years # distance_of_time_in_words(to_time, from_time, include_seconds: true) # => about 6 years # distance_of_time_in_words(Time.now, Time.now) # => less than a minute + # + # With the <tt>scope</tt> you can define a custom scope for Rails lookup + # the translation. + # For example you can define the following in your locale (e.g. en.yml). + # + # datetime: + # distance_in_words: + # short: + # about_x_hours: + # one: 1 hr + # other: '%{count} hr' + # + # See https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml + # for more examples. + # + # Which then will result in the following: + # + # from_time = Time.now + # distance_of_time_in_words(from_time, from_time + 50.minutes, scope: 'datetime.distance_in_words.short') # => 1 hr + # distance_of_time_in_words(from_time, from_time + 3.hours, scope: 'datetime.distance_in_words.short') # => 3 hr def distance_of_time_in_words(from_time, to_time = 0, options = {}) options = { scope: :'datetime.distance_in_words' |