I want to print {{forloop.counter}} with persian or Hindi encoding means to have "۱ ۲ ۳ ۴ .." instead of "1 2 3 4 ...". I searched a lot but I couldn't find any related functions. Would you mind helping me?
Regards
You could use a custom template filter. I'm not familiar enough with Django's l10n library to know if they do this for you.
def devanagari_int(arabic_int):
""" Converts an arabic numeral (ex. 5817) to Devanagari (ex. ५८१७) """
devanagari_nums = ('०','१','२','३','४','५','६','७','८','९')
# arabic_nums = ('۰','١','۲'....)
# farsi_nums = (...)
number = str(arabic_int)
return ''.join(devanagari_nums[int(digit)] for digit in number)
# register your filter, and then:
{{forloop.counter|devanagari_int}}
Make sure you save your filter file as UTF-8 (or instead use the appropriate unicode representations).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With