1 #====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (C) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
15 # Contributors: Thomas Bayen <bayen@gmx.de>
16 # Antti Kaihola <akaihola@siba.fi>
17 # Moritz Bunkus (tex code)
19 # This program is free software; you can redistribute it and/or modify
20 # it under the terms of the GNU General Public License as published by
21 # the Free Software Foundation; either version 2 of the License, or
22 # (at your option) any later version.
24 # This program is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 # GNU General Public License for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write to the Free Software
30 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #======================================================================
33 # Translations and number/date formatting
35 #======================================================================
45 $main::lxdebug->enter_sub();
47 my ($type, $country, $NLS_file) = @_;
54 if ($country && -d "locale/$country") {
56 $self->{countrycode} = $country;
57 if (open(IN, "<", "locale/$country/$NLS_file")) {
58 my $code = join("", <IN>);
63 if (open IN, "<", "locale/$country/charset") {
64 $self->{charset} = <IN>;
67 chomp $self->{charset};
70 $self->{charset} = Common::DEFAULT_CHARSET;
73 my $db_charset = $main::dbcharset || Common::DEFAULT_CHARSET;
75 $self->{iconv} = Text::Iconv->new($self->{charset}, $db_charset);
76 $self->{iconv_english} = Text::Iconv->new('ASCII', $db_charset);
77 $self->{iconv_iso8859} = Text::Iconv->new('ISO-8859-15', $db_charset);
80 $self->{NLS_file} = $NLS_file;
82 push @{ $self->{LONG_MONTH} },
83 ("January", "February", "March", "April",
84 "May ", "June", "July", "August",
85 "September", "October", "November", "December");
86 push @{ $self->{SHORT_MONTH} },
87 (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
89 $main::lxdebug->leave_sub();
98 if (exists $self->{texts}->{$text}) {
99 $text = $self->{iconv}->convert($self->{texts}->{$text});
101 $text = $self->{iconv_english}->convert($text);
105 $text = Form->format_string($text, @_);
112 $main::lxdebug->enter_sub();
114 my ($self, $text) = @_;
116 if (exists $self->{subs}{$text}) {
117 $text = $self->{subs}{$text};
119 if ($self->{countrycode} && $self->{NLS_file}) {
121 "$text not defined in locale/$self->{countrycode}/$self->{NLS_file}");
125 $main::lxdebug->leave_sub();
131 $main::lxdebug->enter_sub();
133 my ($self, $myconfig, $date, $longformat) = @_;
136 my $longmonth = ($longformat) ? 'LONG_MONTH' : 'SHORT_MONTH';
141 $spc = $myconfig->{dateformat};
143 $spc = substr($spc, 1, 1);
146 if ($myconfig->{dateformat} =~ /^yy/) {
147 ($yy, $mm, $dd) = split /\D/, $date;
149 if ($myconfig->{dateformat} =~ /^mm/) {
150 ($mm, $dd, $yy) = split /\D/, $date;
152 if ($myconfig->{dateformat} =~ /^dd/) {
153 ($dd, $mm, $yy) = split /\D/, $date;
156 $date = substr($date, 2);
157 ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
162 $yy = ($yy < 70) ? $yy + 2000 : $yy;
163 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
165 if ($myconfig->{dateformat} =~ /^dd/) {
166 if (defined $longformat && $longformat == 0) {
168 $dd = "0$dd" if ($dd < 10);
169 $mm = "0$mm" if ($mm < 10);
170 $longdate = "$dd$spc$mm$spc$yy";
173 $longdate .= ($spc eq '.') ? ". " : " ";
174 $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
176 } elsif ($myconfig->{dateformat} eq "yyyy-mm-dd") {
178 # Use German syntax with the ISO date style "yyyy-mm-dd" because
179 # Lx-Office is mainly used in Germany or German speaking countries.
180 if (defined $longformat && $longformat == 0) {
182 $dd = "0$dd" if ($dd < 10);
183 $mm = "0$mm" if ($mm < 10);
184 $longdate = "$yy-$mm-$dd";
187 $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
190 if (defined $longformat && $longformat == 0) {
192 $dd = "0$dd" if ($dd < 10);
193 $mm = "0$mm" if ($mm < 10);
194 $longdate = "$mm$spc$dd$spc$yy";
196 $longdate = &text($self, $self->{$longmonth}[$mm]) . " $dd, $yy";
202 $main::lxdebug->leave_sub();
208 $main::lxdebug->enter_sub();
210 my ($self, $myconfig, $date, $longformat) = @_;
213 $main::lxdebug->leave_sub();
218 $spc = $myconfig->{dateformat};
220 $spc = substr($spc, 1, 1);
223 if ($myconfig->{dateformat} =~ /^yy/) {
224 ($yy, $mm, $dd) = split /\D/, $date;
225 } elsif ($myconfig->{dateformat} =~ /^mm/) {
226 ($mm, $dd, $yy) = split /\D/, $date;
227 } elsif ($myconfig->{dateformat} =~ /^dd/) {
228 ($dd, $mm, $yy) = split /\D/, $date;
231 $date = substr($date, 2);
232 ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
237 $yy = ($yy < 70) ? $yy + 2000 : $yy;
238 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
240 $main::lxdebug->leave_sub();
241 return ($yy, $mm, $dd);
245 $main::lxdebug->enter_sub();
247 my ($self, $myconfig, $date, $output_format, $longformat) = @_;
249 $main::lxdebug->leave_sub() and return "" unless ($date);
251 my ($yy, $mm, $dd) = $self->parse_date($myconfig, $date);
253 $output_format =~ /d+/;
254 substr($output_format, $-[0], $+[0] - $-[0]) =
255 sprintf("%0" . (length($&)) . "d", $dd);
257 $output_format =~ /m+/;
258 substr($output_format, $-[0], $+[0] - $-[0]) =
259 sprintf("%0" . (length($&)) . "d", $mm);
261 $output_format =~ /y+/;
262 if (length($&) == 2) {
263 $yy -= $yy >= 2000 ? 2000 : 1900;
265 substr($output_format, $-[0], $+[0] - $-[0]) =
266 sprintf("%0" . (length($&)) . "d", $yy);
268 $main::lxdebug->leave_sub();
270 return $output_format;