from django.template.defaultfilters import stringfilter
from datetime import datetime, timedelta
from django import template

register = template.Library()

@register.filter
def event_time(start, end):
    today = datetime.today ()
    result = ""

    if start == today:
        result += "aujourd'hui "
    else:
        result += "le %s " % start.strftime ("%A %d %B %Y")

    if start.day == end.day and start.month == end.month and start.year == end.year:
        result += "de %s " % start.strftime ("%H:%M")
        result += "à %s " % end.strftime ("%H:%M")
    else:
        result += "à %s" % start.strftime ("%H:%M")
        result += "jusqu'au %s" % end.strftime ("%A %d %B %Y à %H:%M")

    return result


from django.template.defaultfilters import stringfilter
from datetime import datetime, timedelta
from django import template
import locale

register = template.Library()

@register.filter
def event_time(start, end):
    today = datetime.today ()
    result = ""

    # Hack! get the correct user local from the request
    loc = locale.getlocale()
    locale.setlocale(locale.LC_ALL, 'fr_CA.UTF8')

    if start == today:
        result += "Aujourd'hui "
    else:
        result += "Le %s " % start.strftime ("%A %d %B %Y")

    if start.day == end.day and start.month == end.month and start.year == end.year:
        result += "de %s " % start.strftime ("%H:%M")
        result += "à %s " % end.strftime ("%H:%M")
    else:
        result += "à %s" % start.strftime ("%H:%M")
        result += "jusqu'au %s" % end.strftime ("%A %d %B %Y à %H:%M")

    locale.setlocale(locale.LC_ALL, loc)
    return result


Print date in fr_CA locale
hack: Print date in fr_CA locale

  from django.template.defaultfilters import stringfilter
  from datetime import datetime, timedelta
  from django import template
+ import locale
  
  register = template.Library()
  
  @register.filter
  def event_time(start, end):
      today = datetime.today ()
      result = ""
  
+     # Hack! get the correct user local from the request
+     loc = locale.getlocale()
+     locale.setlocale(locale.LC_ALL, 'fr_CA.UTF8')
+ 
      if start == today:
-         result += "aujourd'hui "
+         result += "Aujourd'hui "
      else:
-         result += "le %s " % start.strftime ("%A %d %B %Y")
+         result += "Le %s " % start.strftime ("%A %d %B %Y")
  
      if start.day == end.day and start.month == end.month and start.year == end.year:
          result += "de %s " % start.strftime ("%H:%M")
          result += "à %s " % end.strftime ("%H:%M")
      else:
          result += "à %s" % start.strftime ("%H:%M")
          result += "jusqu'au %s" % end.strftime ("%A %d %B %Y à %H:%M")
  
+     locale.setlocale(locale.LC_ALL, loc)
      return result
  
  
Print date in fr_CA locale
## Code Before:
from django.template.defaultfilters import stringfilter
from datetime import datetime, timedelta
from django import template

register = template.Library()

@register.filter
def event_time(start, end):
    today = datetime.today ()
    result = ""

    if start == today:
        result += "aujourd'hui "
    else:
        result += "le %s " % start.strftime ("%A %d %B %Y")

    if start.day == end.day and start.month == end.month and start.year == end.year:
        result += "de %s " % start.strftime ("%H:%M")
        result += "à %s " % end.strftime ("%H:%M")
    else:
        result += "à %s" % start.strftime ("%H:%M")
        result += "jusqu'au %s" % end.strftime ("%A %d %B %Y à %H:%M")

    return result


## Instruction:
Print date in fr_CA locale
## Code After:
from django.template.defaultfilters import stringfilter
from datetime import datetime, timedelta
from django import template
import locale

register = template.Library()

@register.filter
def event_time(start, end):
    today = datetime.today ()
    result = ""

    # Hack! get the correct user local from the request
    loc = locale.getlocale()
    locale.setlocale(locale.LC_ALL, 'fr_CA.UTF8')

    if start == today:
        result += "Aujourd'hui "
    else:
        result += "Le %s " % start.strftime ("%A %d %B %Y")

    if start.day == end.day and start.month == end.month and start.year == end.year:
        result += "de %s " % start.strftime ("%H:%M")
        result += "à %s " % end.strftime ("%H:%M")
    else:
        result += "à %s" % start.strftime ("%H:%M")
        result += "jusqu'au %s" % end.strftime ("%A %d %B %Y à %H:%M")

    locale.setlocale(locale.LC_ALL, loc)
    return result

