#
##############################################################################
+import logging
+from translate import _
+
+_logger = logging.getLogger(__name__)
+
#-------------------------------------------------------------
#ENGLISH
#-------------------------------------------------------------
-from translate import _
to_19 = ( 'Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six',
'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen',
'Decillion', 'Undecillion', 'Duodecillion', 'Tredecillion', 'Quattuordecillion',
'Sexdecillion', 'Septendecillion', 'Octodecillion', 'Novemdecillion', 'Vigintillion' )
-# convert a value < 100 to English.
def _convert_nn(val):
+ """convert a value < 100 to English.
+ """
if val < 20:
return to_19[val]
for (dcap, dval) in ((k, 20 + (10 * v)) for (v, k) in enumerate(tens)):
return dcap + '-' + to_19[val % 10]
return dcap
-# convert a value < 1000 to english, special cased because it is the level that kicks
-# off the < 100 special case. The rest are more general. This also allows you to
-# get strings in the form of 'forty-five hundred' if called directly.
def _convert_nnn(val):
+ """
+ convert a value < 1000 to english, special cased because it is the level that kicks
+ off the < 100 special case. The rest are more general. This also allows you to
+ get strings in the form of 'forty-five hundred' if called directly.
+ """
word = ''
(mod, rem) = (val % 100, val // 100)
if rem > 0:
end_word = english_number(int(list[1]))
cents_number = int(list[1])
cents_name = (cents_number > 1) and 'Cents' or 'Cent'
- final_result = start_word +' '+units_name+' and ' + end_word +' '+cents_name
- return final_result
+
+ return ' '.join(filter(None, [start_word, units_name, (start_word or units_name) and (end_word or cents_name) and 'and', end_word, cents_name]))
#-------------------------------------------------------------
#TODO: we should use the country AND language (ex: septante VS soixante dix)
#TODO: we should use en by default, but the translation func is yet to be implemented
def amount_to_text(nbr, lang='en', currency='euro'):
- """
- Converts an integer to its textual representation, using the language set in the context if any.
- Example:
- 1654: thousands six cent cinquante-quatre.
+ """ Converts an integer to its textual representation, using the language set in the context if any.
+
+ Example::
+
+ 1654: thousands six cent cinquante-quatre.
"""
import openerp.loglevels as loglevels
# if nbr > 10000000:
-# netsvc.Logger().notifyChannel('translate', netsvc.LOG_WARNING, _("Number too large '%d', can not translate it"))
+# _logger.warning(_("Number too large '%d', can not translate it"))
# return str(nbr)
if not _translate_funcs.has_key(lang):
- loglevels.Logger().notifyChannel('translate', loglevels.LOG_WARNING, _("no translation function found for lang: '%s'" % (lang,)))
+ _logger.warning(_("no translation function found for lang: '%s'"), lang)
#TODO: (default should be en) same as above
lang = 'en'
return _translate_funcs[lang](abs(nbr), currency)
else:
print int_to_text(int(argv[1]), lang)
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: