Hi all,
I am working on internationalization topics, specifically time localization, and have ran into an issue that could be a possible feature inclusion in a future release that I wanted to get others’ opinions on.
One of the popular formats in English to say a space in time relative to the present time would be to use “10 minutes ago”. Right now, DateHelper allows you to correctly get the text “10 minutes” and then override any of that language by creating a yml file similar to the default en datetime translation. The part that is missing is “ago” - so let’s just add in “ago” into the override file right?
The problem becomes this: If the someone uses the distance_of_time_in_words without one of the “to” or “from” specified as Time.now, it doesn’t make sense anymore.
I want to include “ago” for English but allow that relative time to be translated properly. I didn’t want to include a separate translation key for “ago” because that could result in improper translation without context. In addition, other languages have prefixes instead of suffixes when specifying relative time.
My proposal is to add some additional options for the distance_of_time_in_words method in DateHelper
-
:include_prefix (default: false)
-
:include_suffix (default: false)
In the default yml file for datetime distance, there would be additional keys - :prefix and :suffix
For English, suffix would be “ago” and prefix would be “” - this would allow users to customize not only the language used for the distance of time in words, but also any prefix or suffix used for the language.
Now, if I want my “10 minutes ago”, instead of specifying
<%= time_ago_in_words(Time.now) %> ago
we can now specify
<%= time_ago_in_words(Time.now, :include_prefix => true) %>
Thoughts?
-Andrew