import sql-ledger 2.4.4
[freeside.git] / sql-ledger / locale / hu / Num2text
1 #=====================================================================\r
2 # SQL-Ledger Accounting\r
3 # Copyright (C) 2001\r
4 #\r
5 #  Author: Dieter Simader\r
6 #   Email: dsimader@sql-ledger.org\r
7 #     Web: http://www.sql-ledger.org\r
8 #  Modified by: Medgyesi Aniko\r
9 #  **********************************\r
10 #  *#MEA1 * Hungarian version       *\r
11 #  **********************************\r
12 #  Contributors:\r
13 #\r
14 # This program is free software; you can redistribute it and/or modify\r
15 # it under the terms of the GNU General Public License as published by\r
16 # the Free Software Foundation; either version 2 of the License, or\r
17 # (at your option) any later version.\r
18 #\r
19 # This program is distributed in the hope that it will be useful,\r
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of\r
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
22 # GNU General Public License for more details.\r
23 # You should have received a copy of the GNU General Public License\r
24 # along with this program; if not, write to the Free Software\r
25 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
26 #=====================================================================\r
27 #\r
28 # this is the default code for the Check package\r
29 #\r
30 #=====================================================================\r
31 \r
32 sub init {\r
33   my $self = shift;\r
34 #MEA1 English number ignored\r
35 #   %{ $self->{numbername} } =\r
36 #      (0 => 'Zero',\r
37 #       1 => 'One',\r
38 #       2 => 'Two',\r
39 #             3 => 'Three',\r
40 #                   4 => 'Four',\r
41 #                   5 => 'Five',\r
42 #                   6 => 'Six',\r
43 #                   7 => 'Seven',\r
44 #                   8 => 'Eight',\r
45 #                   9 => 'Nine',\r
46 #                  10 => 'Ten',\r
47 #                  11 => 'Eleven',\r
48 #                  12 => 'Twelve',\r
49 #                  13 => 'Thirteen',\r
50 #                  14 => 'Fourteen',\r
51 #                  15 => 'Fifteen',\r
52 #                  16 => 'Sixteen',\r
53 #                  17 => 'Seventeen',\r
54 #                  18 => 'Eighteen',\r
55 #                  19 => 'Nineteen',\r
56 #                  20 => 'Twenty',\r
57 #                  30 => 'Thirty',\r
58 #                  40 => 'Forty',\r
59 #                  50 => 'Fifty',\r
60 #                  60 => 'Sixty',\r
61 #                  70 => 'Seventy',\r
62 #                  80 => 'Eighty',\r
63 #                  90 => 'Ninety',\r
64 #   10**2 => 'Hundred',\r
65 #   10**3 => 'Thousand',\r
66 #               10**6 => 'Million',\r
67 #               10**9 => 'Billion',\r
68 #   10**12 => 'Trillion',\r
69 # );\r
70 #MEA1BEG Hungarian numbers\r
71   %{ $self->{numbername} } =\r
72            (0 => 'Nulla',\r
73             1 => 'egy',\r
74             2 => 'kettõ',\r
75                 3 => 'három',\r
76                     4 => 'négy',\r
77                     5 => 'öt',\r
78                     6 => 'hat',\r
79                     7 => 'hét',\r
80                     8 => 'nyolc',\r
81                     9 => 'kilenc',\r
82                    10 => 'tíz',\r
83                    11 => 'tizenegy',\r
84                    12 => 'tizenkettõ',\r
85                    13 => 'tizenhárom',\r
86                    14 => 'tizennégy',\r
87                    15 => 'tizenöt',\r
88                    16 => 'tizenhat',\r
89                    17 => 'tizenhét',\r
90                    18 => 'tizennyolc',\r
91                    19 => 'tizenkilenc',\r
92                    20 => 'húsz',\r
93                    21 => 'huszonegy',\r
94                    22 => 'huszonkettõ',\r
95                    23 => 'huszonhárom',\r
96                    24 => 'huszonnégy',\r
97                    25 => 'huszonöt',\r
98                    26 => 'huszonhat',\r
99                    27 => 'huszonhét',\r
100                    28 => 'huszonnyolc',\r
101                    29 => 'huszonkilenc',\r
102                    30 => 'harminc',\r
103                    40 => 'negyven',\r
104                    50 => 'ötven',\r
105                    60 => 'hatvan',\r
106                    70 => 'hetven',\r
107                    80 => 'nyolcvan',\r
108                    90 => 'kilencven',\r
109         10**2 => 'száz',\r
110         10**3 => 'ezer',\r
111                 10**6 => 'millió',\r
112                 10**9 => 'milliárd',\r
113             10**12 => 'billió',\r
114                 );\r
115 #MEA1END\r
116 \r
117 }\r
118 \r
119 \r
120 sub num2text {\r
121   my ($self, $amount) = @_;\r
122 \r
123   return $self->{numbername}{0} unless $amount;\r
124 \r
125   my @textnumber = ();\r
126 \r
127   # split amount into chunks of 3\r
128   my @num = reverse split //, abs($amount);\r
129   my @numblock = ();\r
130   my @a;\r
131   my $i;\r
132 #MEA1BEG\r
133   my $res;\r
134 #MEA1END\r
135   while (@num) {\r
136     @a = ();\r
137     for (1 .. 3) {\r
138       push @a, shift @num;\r
139     }\r
140     push @numblock, join / /, reverse @a;\r
141   }\r
142   while (@numblock) {\r
143     $i = $#numblock;\r
144     @num = split //, $numblock[$i];\r
145 \r
146     if ($numblock[$i] == 0) {\r
147       pop @numblock;\r
148       next;\r
149     }\r
150     if ($numblock[$i] > 99) {\r
151       push @textnumber, $self->{numbername}{$num[0]};\r
152 \r
153       # add hundred designation\r
154       push @textnumber, $self->{numbername}{10**2};\r
155 \r
156       # reduce numblock\r
157       $numblock[$i] -= $num[0] * 100;\r
158 \r
159     }\r
160 \r
161     $numblock[$i] *= 1;\r
162     if ($numblock[$i] > 9) {\r
163       # tens\r
164       push @textnumber, $self->format_ten($numblock[$i]);\r
165     } elsif ($numblock[$i] > 0) {\r
166       # ones\r
167       push @textnumber, $self->{numbername}{$numblock[$i]};\r
168     }\r
169 \r
170     # add thousand, million\r
171     if ($i) {\r
172 #MEA1BEG above 2000 need hyphen between treegroups\r
173 #    if ($numblock[$i] > 9) {\r
174 #       push @textnumber, $self->format_ten($numblock[$i]);\r
175 #     } elsif ($numblock[$i] > 0) {\r
176 #       push @textnumber, $self->{numbername}{$numblock[$i]};\r
177 #     }\r
178       if ($i==1 && $amount < 2000){\r
179 \r
180         $num = 10**($i * 3);\r
181         push @textnumber, $self->{numbername}{$num};\r
182       } else  {\r
183 \r
184           $num = 10**($i * 3);\r
185           push @textnumber, $self->{numbername}{$num}."-";\r
186       }\r
187 #MEA1END\r
188     }\r
189 \r
190     pop @numblock;\r
191 \r
192   }\r
193 #MEA1BEG First charachter is uppercase\r
194 # join '', @textnumber;\r
195   $res=ucfirst join '', @textnumber;\r
196 #MEA1END\r
197 #MEA1BEG  remove last hyphen\r
198   $res=~s/(\-)$//;\r
199   return $res;\r
200 #MEA1END\r
201 \r
202 \r
203 }\r
204 \r
205 \r
206 sub format_ten {\r
207   my ($self, $amount) = @_;\r
208 \r
209   my $textnumber = "";\r
210   my @num = split //, $amount;\r
211 #MEA1BEG above 30 not above 20\r
212 # if ($amount > 30) {\r
213   if ($amount > 30) {\r
214 #MEA1END\r
215     $textnumber = $self->{numbername}{$num[0]*10};\r
216     $amount = $num[1];\r
217   } else {\r
218     $textnumber = $self->{numbername}{$amount};\r
219     $amount = 0;\r
220   }\r
221 \r
222   $textnumber .= "".$self->{numbername}{$amount} if $amount;\r
223 \r
224   $textnumber;\r
225 \r
226 }\r
227 \r
228 \r
229 1;\r
230 \r
231 \r
232 \r