1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 #-------------------------------------------------------------
25 #-------------------------------------------------------------
28 0: '', 1:'One', 2:'Two', 3:'Three', 4:'Four', 5:'Five', 6:'Six', 7:'Seven', 8:'Eight', 9:'Nine',
29 10:'Ten', 11:'Eleven', 12:'Twelve', 13:'Thirteen', 14:'Forteen', 15:'Fifteen', 16:'Sixteen', 17:"Seventeen",18:"Eighteen",19:"Nineteen",
33 1: 'Ten', 2: 'Twenty ', 3:'Thirty', 4:'Forty', 5:'Fifty', 6: 'Sixty', 7 : 'Seventy', 8:'Eighty' ,9: 'Ninety'}
36 0:'',1: 'One Hundred', 2: 'Two Hundred', 3: 'Three Hundred', 4 :'Four Hundred', 5: 'Five Hundred', 6: 'Six Hundred', 7 :'Seven Hundred', 8:' Eight Hundred ', 9:'Nine Hundred '
40 0:'',1: 'One Thousand'
47 def _100_to_text(number):
52 return tens[number / 10]+'-'+ones[number % 10]
54 return tens[number / 10]
56 def _1000_to_text(number):
57 d = _100_to_text(number % 100)
60 return hundred[d2]+' '+d
62 return hundred[d2]+'s'
64 return hundred[d2] or d
66 def _10000_to_text(number):
69 part1 = _1000_to_text(number % 1000)
70 part2 = thousands.get(number / 1000, _1000_to_text(number / 1000)+' Thousands')
75 def _1000000_to_text(number):
78 part1 = _10000_to_text(number % 100000)
79 part2 = lacs.get(number / 100000, _10000_to_text(number / 100000)+' Lacs')
85 def amount_to_text(number, currency):
86 lacs_number = int(number)
91 lacs = _1000000_to_text(lacs_number)
92 lacs = lacs_number and '%s %s' % (lacs, units_name) or ''
94 units_number = int(number * 10000) % 10000
95 units = _10000_to_text(units_number)
96 units = units_number and '%s %s' % (units, units_name) or ''
98 cents_number = int(number * 100) % 100
99 cents_name = (cents_number > 1) and 'cents' or 'cent'
100 cents = _100_to_text(cents_number)
101 cents = cents_number and '%s %s' % (cents, cents_name) or ''
105 #-------------------------------------------------------------
107 #-------------------------------------------------------------
109 _translate_funcs = {'en' : amount_to_text}
111 #TODO: we should use the country AND language (ex: septante VS soixante dix)
112 #TODO: we should use en by default, but the translation func is yet to be implemented
113 def amount_to_text(nbr, lang='en', currency='euro'):
115 Converts an integer to its textual representation, using the language set in the context if any.
117 1654: thousands six cent cinquante-quatre.
121 netsvc.Logger().notifyChannel('translate', netsvc.LOG_WARNING, _("Number too large '%d', can not translate it"))
124 if not _translate_funcs.has_key(lang):
125 netsvc.Logger().notifyChannel('translate', netsvc.LOG_WARNING, _("no translation function found for lang: '%s'" % (lang,)))
126 #TODO: (default should be en) same as above
128 return _translate_funcs[lang](nbr, currency)
130 if __name__=='__main__':
135 for i in range(1,200):
136 print i, ">>", int_to_text(i, lang)
137 for i in range(200,999999,139):
138 print i, ">>", int_to_text(i, lang)
140 print int_to_text(int(argv[1]), lang)