title: How to localize humanized time formatting
body: <p>How can I localize to get nice humanized output of the time for an article like</p>
  <blockquote>
  <p>Today</p>
  <p>16:48</p>
  </blockquote>
  <p>or</p>
  <blockquote>
  <p>Yesterday</p>
  <p>17:10</p>
  </blockquote>
  <p>or</p>
  <blockquote>
  <p>13 Dec</p>
  <p>11:20</p>
  </blockquote>
  <pre><code>from webapp2_extras.i18n import gettext as _
  import datetime
  from datetime import date, datetime, time
  from babel.dates import format_date, format_datetime, format_time
  from babel.numbers import format_number, format_decimal, format_percent
  
  def datetimeformat_jinja(value, format='%H:%M / %d-%m-%Y', locale='en'):
      now= datetime.now()
      if datetime.date(value) == datetime.date(now):
        info= _('Today')
      elif (now - value).days &lt; 2:
        info= _('Yesterday')
      else:
        info=format_datetime(value, &quot;MMMM dd&quot;, locale=locale)
      return info+'&lt;br&gt;'+format_time(value, 'hh:mm', locale=locale)
  </code></pre>
  <p>Using the code above I can make a filter for an entity's time that will display humanized output:</p>
  <pre><code>{{ entity.modified|datetimeformat_jinja(locale='pt_BR') }}
  </code></pre>
  <p>But how do I localize the string &quot;Today&quot; and &quot;Yesterday&quot; and how do I get the abbrieviated form from babel like Jan instead of january, Feb instead of february and how do I add timezones to this project when I know which country the entity was in at the time of modification? I have a variable entity.url that tells we which domain it was since my app serves several domains, so it's basically just the timezones depending on entity.url (Brazil timezone and India timezone) and my basic localization is mainly for Brazilian portuguese and English but it should work for more ie it should be easy to add and languages and switch to a language.</p>
  <p>Thank you for any answer of comment</p>
  <h2>Update</h2>
  <p>It renders correctly now but I could not take it very directly from django's timesince nad I could not yet make timezones work. But the only part left now is timezones, I think:</p>
  <pre><code>def datetimeformat_jinja(value, format='%H:%M / %d-%m-%Y', locale='en'):
      now= datetime.now()
      info = None
      if datetime.date(value) == datetime.date(now):
        info= _('Today')
      elif (now - value).days &lt; 2:
        info= _('Yesterday')
      else:
        month = value.month
        if month == 1:
          info = str(value.day)+' '+_('Jan.')
        elif month == 2:
          info = str(value.day)+' '+_('Feb.')
        elif month == 3:
          info = str(value.day)+' '+_('Mar.')
        elif month == 4:
          info = str(value.day)+' '+_('April')
        elif month == 5:
          info = str(value.day)+' '+_('May')
        elif month == 6:
          info = str(value.day)+' '+_('June')
        elif month == 7:
          info = str(value.day)+' '+_('July')
        elif month == 8:
          info = str(value.day)+' '+_('Aug.')
        elif month == 9:
          info = str(value.day)+' '+_('Sep.')
        elif month == 10:
          info = str(value.day)+' '+_('Oct.')
        elif month == 11:
          info = str(value.day)+' '+_('Nov.')
        else:
          info = str(value.day)+' '+_('Dec.')
      return info+'&lt;br&gt;'+format_time(value, 'hh:mm', locale=locale)
  </code></pre>
  <p>I had to do like above to get the translated short form of months eg Dez. for Dezember in Brazilia Portuguese) and now it localizes better:</p>
  <p><img src="https://i.stack.imgur.com/BiWHi.png" alt="enter image description here" />
  Above is before and the following is with the localization in Brazilian Portuguese
  <img src="https://i.stack.imgur.com/djT4J.png" alt="enter image description here" /></p>