Skip to content

Commit

Permalink
[Core] Used num2words to convert numbers to words.
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbestigrou committed Aug 22, 2017
1 parent 61730e6 commit 5119322
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -15,7 +15,7 @@
"typogrify.templatetags",
],
install_requires=[
'smartypants>=1.8.3'
'smartypants>=1.8.3', 'num2words'
],
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down
40 changes: 14 additions & 26 deletions typogrify/templatetags/typogrify_tags.py
Expand Up @@ -5,12 +5,14 @@

import smartypants as _smartypants
import typogrify.titlecase as _titlecase
from num2words import num2words

from django import template
from django.conf import settings
from django.utils.encoding import force_text
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext, ungettext
from django.utils.translation import ugettext, ungettext, get_language

register = template.Library()

Expand Down Expand Up @@ -451,9 +453,7 @@ def super_fuzzydate(value):
@register.filter
def text_whole_number(value):
"""
Takes a whole number, and if its less than 10, writes it out in text.
english only for now.
Takes a whole number and writes it out in text.
"""

try:
Expand All @@ -462,28 +462,16 @@ def text_whole_number(value):
# Not an int
return value

if value <= 10:
if value == 1:
value = "one"
elif value == 2:
value = "two"
elif value == 3:
value = "three"
elif value == 4:
value = "four"
elif value == 5:
value = "five"
elif value == 6:
value = "six"
elif value == 7:
value = "seven"
elif value == 8:
value = "eight"
elif value == 9:
value = "nine"
elif value == 10:
value = "ten"
return value
language = get_language()

if language:
result = num2words(value, lang=language)
else:
result = num2words(value)

return result


text_whole_number.is_safe = True


Expand Down

0 comments on commit 5119322

Please sign in to comment.