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 #======================================================================
42 $main::lxdebug->enter_sub();
44 my ($type, $country, $NLS_file) = @_;
47 if ($country && -d "locale/$country") {
49 $self->{countrycode} = $country;
50 if (open(IN, "locale/$country/$NLS_file")) {
51 my $code = join("", <IN>);
57 $self->{NLS_file} = $NLS_file;
59 push @{ $self->{LONG_MONTH} },
60 ("January", "February", "March", "April",
61 "May ", "June", "July", "August",
62 "September", "October", "November", "December");
63 push @{ $self->{SHORT_MONTH} },
64 (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
66 $main::lxdebug->leave_sub();
72 my ($self, $text) = @_;
74 return (exists $self->{texts}{$text}) ? $self->{texts}{$text} : $text;
78 $main::lxdebug->enter_sub();
80 my ($self, $text) = @_;
82 if (exists $self->{subs}{$text}) {
83 $text = $self->{subs}{$text};
85 if ($self->{countrycode} && $self->{NLS_file}) {
87 "$text not defined in locale/$self->{countrycode}/$self->{NLS_file}");
91 $main::lxdebug->leave_sub();
97 $main::lxdebug->enter_sub();
99 my ($self, $myconfig, $date, $longformat) = @_;
102 my $longmonth = ($longformat) ? 'LONG_MONTH' : 'SHORT_MONTH';
107 $spc = $myconfig->{dateformat};
109 $spc = substr($spc, 1, 1);
112 if ($myconfig->{dateformat} =~ /^yy/) {
113 ($yy, $mm, $dd) = split /\D/, $date;
115 if ($myconfig->{dateformat} =~ /^mm/) {
116 ($mm, $dd, $yy) = split /\D/, $date;
118 if ($myconfig->{dateformat} =~ /^dd/) {
119 ($dd, $mm, $yy) = split /\D/, $date;
122 $date = substr($date, 2);
123 ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
128 $yy = ($yy < 70) ? $yy + 2000 : $yy;
129 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
131 if ($myconfig->{dateformat} =~ /^dd/) {
132 if (defined $longformat && $longformat == 0) {
134 $dd = "0$dd" if ($dd < 10);
135 $mm = "0$mm" if ($mm < 10);
136 $longdate = "$dd$spc$mm$spc$yy";
139 $longdate .= ($spc eq '.') ? ". " : " ";
140 $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
142 } elsif ($myconfig->{dateformat} eq "yyyy-mm-dd") {
144 # Use German syntax with the ISO date style "yyyy-mm-dd" because
145 # Lx-Office is mainly used in Germany or German speaking countries.
146 if (defined $longformat && $longformat == 0) {
148 $dd = "0$dd" if ($dd < 10);
149 $mm = "0$mm" if ($mm < 10);
150 $longdate = "$yy-$mm-$dd";
153 $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
156 if (defined $longformat && $longformat == 0) {
158 $dd = "0$dd" if ($dd < 10);
159 $mm = "0$mm" if ($mm < 10);
160 $longdate = "$mm$spc$dd$spc$yy";
162 $longdate = &text($self, $self->{$longmonth}[$mm]) . " $dd, $yy";
168 $main::lxdebug->leave_sub();
174 $main::lxdebug->enter_sub();
176 my ($self, $myconfig, $date, $longformat) = @_;
179 $main::lxdebug->leave_sub();
184 $spc = $myconfig->{dateformat};
186 $spc = substr($spc, 1, 1);
189 if ($myconfig->{dateformat} =~ /^yy/) {
190 ($yy, $mm, $dd) = split /\D/, $date;
191 } elsif ($myconfig->{dateformat} =~ /^mm/) {
192 ($mm, $dd, $yy) = split /\D/, $date;
193 } elsif ($myconfig->{dateformat} =~ /^dd/) {
194 ($dd, $mm, $yy) = split /\D/, $date;
197 $date = substr($date, 2);
198 ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
203 $yy = ($yy < 70) ? $yy + 2000 : $yy;
204 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
206 $main::lxdebug->leave_sub();
207 return ($yy, $mm, $dd);
211 $main::lxdebug->enter_sub();
213 my ($self, $myconfig, $date, $output_format, $longformat) = @_;
215 $main::lxdebug->leave_sub() and return "" unless ($date);
217 my ($yy, $mm, $dd) = $self->parse_date($myconfig, $date);
219 $output_format =~ /d+/;
220 substr($output_format, $-[0], $+[0] - $-[0]) =
221 sprintf("%0" . (length($&)) . "d", $dd);
223 $output_format =~ /m+/;
224 substr($output_format, $-[0], $+[0] - $-[0]) =
225 sprintf("%0" . (length($&)) . "d", $mm);
227 $output_format =~ /y+/;
228 if (length($&) == 2) {
229 $yy -= $yy >= 2000 ? 2000 : 1900;
231 substr($output_format, $-[0], $+[0] - $-[0]) =
232 sprintf("%0" . (length($&)) . "d", $yy);
234 $main::lxdebug->leave_sub();
236 return $output_format;