Allow call to other convertes as to_currency, to_year

There are at least to issues related with questions about how to use other convertes.
This changes should allow the use of this converters
This commit is contained in:
Ernesto Rodriguez Ortiz
2017-09-29 15:29:25 -04:00
parent 39356b495d
commit 49a39fc253

View File

@@ -63,7 +63,10 @@ CONVERTER_CLASSES = {
'vi_VN': lang_VN.Num2Word_VN()
}
def num2words(number, ordinal=False, lang='en'):
CONVERTES_TYPES = ['cardinal', 'ordinal', 'year', 'currency']
def num2words(number, ordinal=False, lang='en', to='cardinal'):
# We try the full language first
if lang not in CONVERTER_CLASSES:
# ... and then try only the first 2 letters
@@ -71,7 +74,11 @@ def num2words(number, ordinal=False, lang='en'):
if lang not in CONVERTER_CLASSES:
raise NotImplementedError()
converter = CONVERTER_CLASSES[lang]
# backwards compatible
if ordinal:
return converter.to_ordinal(number)
else:
return converter.to_cardinal(number)
if to not in CONVERTES_TYPES:
raise NotImplementedError()
return getattr(converter, 'to_{}'.format(to))(number)