Skip to content

Instantly share code, notes, and snippets.

@navilan
Created September 7, 2012 03:48
Show Gist options
  • Save navilan/3662902 to your computer and use it in GitHub Desktop.
Save navilan/3662902 to your computer and use it in GitHub Desktop.
Localized dates for hyde
# -*- coding: utf-8 -*-
from hyde.plugin import Plugin
from jinja2 import contextfunction, Markup
@contextfunction
def localtime(context, val, lc):
import locale, datetime
current = locale.getlocale()
locale.setlocale(locale.LC_ALL, lc)
result = val.strftime(locale.nl_langinfo(locale.D_T_FMT))
locale.setlocale(locale.LC_ALL, current)
return Markup(result.decode('utf-8'))
@contextfunction
def frenchtime(context, val):
return localtime(context, val, ('fr_FR', 'utf-8'))
class SiteDefaults(Plugin):
def template_loaded(self, template):
self.template = template
template.env.globals['localtime'] = localtime
template.env.globals['frenchtime'] = frenchtime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment