~anybox/aeroo/openerp6

« back to all changes in this revision

Viewing changes to report_aeroo/ctt_languages/en_US/__init__.py

  • Committer: root
  • Date: 2013-05-16 15:46:46 UTC
  • Revision ID: root@erp.kndati.lv-20130516154646-5lesr8tyzl1vdc0k
1.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf8 -*-
 
3
# en_US
 
4
 
 
5
from report_aeroo.ctt_objects import ctt_language
 
6
 
 
7
class en_US(ctt_language):
 
8
    def _init_lang(self):
 
9
        # language name
 
10
        self.name = 'en_US'
 
11
        # digits - masculine, singular
 
12
        self.digits_sng_msc = [u'zero', u'one', u'two', u'three', u'four',
 
13
                               u'five', u'six', u'seven', u'eight', u'nine']
 
14
        # tens - masculine, singular
 
15
        self.tens_sng_msc = [u'', u'one', u'twen', u'thir', u'four', u'fif',
 
16
                             u'six', u'seven', u'eigh', u'nine']
 
17
        # teens - masculine
 
18
        self.teens = [u'ten', u'eleven', u'twelve', u'thirteen', u'fourteen',
 
19
                      u'fifteen', u'sixteen', u'seventeen', u'eighteen',
 
20
                      u'nineteen']
 
21
        # multiplier - masculine, singular
 
22
        self.multi_sng_msc = [u' hundred', u' thousand', u' million',
 
23
                              u' billion']
 
24
        # multiplier - masculine, plural
 
25
        self.multi_plr_msc = [u' hundreds', u' thousands', u' millions',
 
26
                              u' billions']
 
27
        
 
28
        # next line is needed for correct loading of currencies 
 
29
        import currencies
 
30
        return currencies
 
31
 
 
32
 
 
33
    def wordify(self, chunk, chunknr, gender):
 
34
        if gender == 'm':
 
35
            number = self.digits_sng_msc
 
36
        elif gender == 'f':
 
37
            number = self.digits_sng_fem
 
38
        elif gender == 'n':
 
39
            number = self.digits_sng_neu
 
40
        words = u''
 
41
        digit1 = u''
 
42
        digit2 = u''
 
43
        digit3 = u''
 
44
        chunklength = len(chunk)
 
45
        # placing digits in right places
 
46
        if chunklength == 1:
 
47
            digit3 = chunk[0 : 1]
 
48
        if chunklength == 2:
 
49
            digit2 = chunk[0 : 1]
 
50
            digit3 = chunk[1 : 2]
 
51
        if chunklength == 3:
 
52
            digit1 = chunk[0 : 1]
 
53
            digit2 = chunk[1 : 2]
 
54
            digit3 = chunk[-1]
 
55
        # processing zero
 
56
        if chunklength == 1 and digit3  == '0' :
 
57
            return number[0]
 
58
        # processing hundreds
 
59
        if chunklength == 3 :
 
60
            if digit1 == '1' :
 
61
                words += self.digits_sng_msc[int(digit1)] + self.multi_sng_msc[0]
 
62
            else :
 
63
                if int(digit1) >= 1 : words += self.digits_sng_msc[int(digit1)] + self.multi_plr_msc[0]
 
64
        # processing tens
 
65
        if chunklength > 1:
 
66
            spacer = ''
 
67
            if len(words) > 0 : spacer = u' '
 
68
            if digit2 == '1':
 
69
                words += spacer + self.teens[int(digit3)]
 
70
            else:
 
71
                if int(digit2) > 1 and int(digit2) > 0:
 
72
                    words += spacer + self.tens_sng_msc[int(digit2)] + u'ty'
 
73
 
 
74
        # processing ones
 
75
        if chunklength > 0 and digit2 != '1' :
 
76
            spacer = ''
 
77
            if len(words) > 0: spacer = u' '
 
78
            if int(digit3) > 0:
 
79
                words += spacer + number[int(digit3)]
 
80
        # end processing
 
81
        if len(words) > 0 :
 
82
            if digit3 == '1' and chunknr > 0:
 
83
                return words + self.multi_sng_msc[chunknr]
 
84
            elif digit3 != '1' and chunknr > 0:
 
85
                return words + self.multi_sng_msc[chunknr]
 
86
            else:
 
87
                return words
 
88
        else:
 
89
            return ''
 
90
 
 
91
en_US()