from django import template

register = template.Library()

PERSIAN_DIGITS = str.maketrans('0123456789,', '۰۱۲۳۴۵۶۷۸۹٬')


@register.filter
def fa_number(value):
    try:
        rendered = f'{int(value):,}'
    except (TypeError, ValueError):
        rendered = str(value or '')
    return rendered.translate(PERSIAN_DIGITS)


@register.filter
def toman(value):
    return f'{fa_number(value)} تومان'
