mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Merge pull request #95 from savoirfairelinux/allow_call_to_other_converters
Allow call to other convertes as to_currency, to_year
This commit is contained in:
@@ -70,7 +70,10 @@ CONVERTER_CLASSES = {
|
|||||||
'uk': lang_UK.Num2Word_UK()
|
'uk': lang_UK.Num2Word_UK()
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
# We try the full language first
|
||||||
if lang not in CONVERTER_CLASSES:
|
if lang not in CONVERTER_CLASSES:
|
||||||
# ... and then try only the first 2 letters
|
# ... and then try only the first 2 letters
|
||||||
@@ -78,7 +81,11 @@ def num2words(number, ordinal=False, lang='en'):
|
|||||||
if lang not in CONVERTER_CLASSES:
|
if lang not in CONVERTER_CLASSES:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
converter = CONVERTER_CLASSES[lang]
|
converter = CONVERTER_CLASSES[lang]
|
||||||
|
# backwards compatible
|
||||||
if ordinal:
|
if ordinal:
|
||||||
return converter.to_ordinal(number)
|
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