""" template filter """
from django import template
import locale

register = template.Library()


@register.filter(name="currency")
def currency(value):
    """ convert value to a nice looking currency """
    try:
        locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
    except Exception:
        locale.setlocale(locale.LC_ALL, "")
    loc = locale.localeconv()
    return locale.currency(value, loc["currency_symbol"], grouping=True)
