mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user