<p>(Moving <a href="https://trac.openstreetmap.org/ticket/4968" rel="nofollow">https://trac.openstreetmap.org/ticket/4968</a> here for better visibility.)</p>
<p>In rails there is a <a href="https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-time_ago_in_words" rel="nofollow"><code>time_ago_in_words</code></a> helper (aka <code>distance_of_time_in_words_to_now</code>) that we use extensively. The strings it returns are actually just the same as the <a href="https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words" rel="nofollow"><code>distance_of_time_in_words</code></a> helper, e.g. "3 years" or "about 1 hour"; that is, they doesn't come with 'ago' attached.</p>
<p>The <a href="https://github.com/rails/rails/blob/b9ca94caea2ca6a6cc09abaffaad67b447134079/actionview/lib/action_view/helpers/date_helper.rb#L95">logic behind the helper</a> is fairly complex. The <a href="https://github.com/svenfuchs/rails-i18n/blob/86942a876dfe5c53782dcc1b117acb946099c674/rails/locale/en.yml#L64">default translations come from the rails-i18n</a> gem, we don't control them ourselves.</p>
<p>We then use these "distance_in_words" strings to create what I'll refer to as "distance_in_words_ago" strings. In English this is very easy, since every possible output of the helper can just have "ago" tacked on the end. For example</p>
<ul>
<li>English: "3 years" -> "3 years <strong>ago</strong>"</li>
</ul>
<p>However, this is not the case in other languages, where to be gramatically correct, in certain cases the original "distance_in_words" needs tweaking. For example:</p>
<ul>
<li>Hungarian: "2 óra" -> "2 ór<strong>ája</strong>"</li>
<li>German: "2 Tage" -> "<strong>vor</strong> 2 Tage<strong>n</strong>"</li>
</ul>
<p>Other people identified the problem many years ago, and so since rails 3.2 the <code>time_ago_in_words</code> helper accepts a <code>:scope</code>, which allows you to pick a different i18n scope for the localisation. For example, instead of using the default <code>en.datetime.distance_in_words</code> from the rails-i18n gem, we could define our own <code>distance_in_words_ago</code> hierarchy:</p>
<pre><code>en:
  datetime:
    distance_in_words_ago:
      about_x_hours:
        one: about 1 hour ago
        other: about %{count} hours ago
      about_x_months:
        one: about 1 month ago
        ...
</code></pre>
<p>We would then update our views, so instead of using the output from the helper in a '.ago' translation, we would set the i18n scope in the helper, and use the output directly. For example:</p>
<div class="highlight highlight-source-diff"><pre>       <% end %>
<span class="pl-md"><span class="pl-md">-</span>      ... <%= t ".ago", :time_in_words_ago => time_ago_in_words(trace.timestamp) %></span></span>
<span class="pl-mi1"><span class="pl-mi1">+</span>      ... <%= time_ago_in_words(trace.timestamp, :scope => :'datetime.distance_in_words_ago') %></span></span>
       <%= link_to_if trace.inserted?, t(".map"), { :controller => "site", :action => "index", :mlat => trace.latitude, :mlon => trace.longitude, :anchor => "map=14/#{trace.latitude}/#{trace.longitude}" }, { :title => t(".view_map") } %> /
</pre></div>
<p>This means that our translators could translate all of the 'distance_in_words_ago' strings in a grammatically correct fashion.</p>
<p>Ultimately, this could also be fixed by two upstream changes. The first would be for the rails-i18n gem to include a 'distance_in_words_ago' translation hierarchy itself, which could be used by hundreds of projects beyond ours. And the secondly, the <code>time_ago_in_words</code> ActionView helper could then return 'distance_in_words_ago' style strings by default, which I think would be more helpful than now. But unless there's any strong opinions, I would suggest we fix this locally first.</p>
<p>My proposal it therefore:</p>
<ul>
<li>Add an <code>en.datetime.distance_in_words_ago</code> hierarchy to our own <code>en.yml</code>.</li>
<li>Give the translators a few weeks opportunity to translate them.</li>
<li>Update our usage of the <code>time_ago_in_words</code> and <code>distance_of_time_in_words_to_now</code> helpers to use the new hierarchy using the scope parameter.</li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/issues/2255?email_source=notifications&email_token=AAK2OLMZHCPUT4ZUOMHYP4DP2DRXVA5CNFSM4HXIJ5T2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GZBOOGA">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLMOJ2PLO5KQO64MFXLP2DRXVANCNFSM4HXIJ5TQ">mute the thread</a>.<img src="https://github.com/notifications/beacon/AAK2OLOOXA3PDSCWNTX3EA3P2DRXVA5CNFSM4HXIJ5T2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GZBOOGA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/issues/2255?email_source=notifications\u0026email_token=AAK2OLMZHCPUT4ZUOMHYP4DP2DRXVA5CNFSM4HXIJ5T2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GZBOOGA",
"url": "https://github.com/openstreetmap/openstreetmap-website/issues/2255?email_source=notifications\u0026email_token=AAK2OLMZHCPUT4ZUOMHYP4DP2DRXVA5CNFSM4HXIJ5T2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GZBOOGA",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>