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;
 
  74     $db_charset ||= Common::DEFAULT_CHARSET;
 
  75     $self->{iconv} = Text::Iconv->new($self->{charset}, $db_charset);
 
  76     $self->{iconv_english} = Text::Iconv->new("ASCII", $db_charset);
 
  79   $self->{NLS_file} = $NLS_file;
 
  81   push @{ $self->{LONG_MONTH} },
 
  82     ("January",   "February", "March",    "April",
 
  83      "May ",      "June",     "July",     "August",
 
  84      "September", "October",  "November", "December");
 
  85   push @{ $self->{SHORT_MONTH} },
 
  86     (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
 
  88   $main::lxdebug->leave_sub();
 
  97   if (exists $self->{texts}->{$text}) {
 
  98     $text = $self->{iconv}->convert($self->{texts}->{$text});
 
 100     $text = $self->{iconv_english}->convert($text);
 
 104     $text = Form->format_string($text, @_);
 
 111   $main::lxdebug->enter_sub();
 
 113   my ($self, $text) = @_;
 
 115   if (exists $self->{subs}{$text}) {
 
 116     $text = $self->{subs}{$text};
 
 118     if ($self->{countrycode} && $self->{NLS_file}) {
 
 120          "$text not defined in locale/$self->{countrycode}/$self->{NLS_file}");
 
 124   $main::lxdebug->leave_sub();
 
 130   $main::lxdebug->enter_sub();
 
 132   my ($self, $myconfig, $date, $longformat) = @_;
 
 135   my $longmonth = ($longformat) ? 'LONG_MONTH' : 'SHORT_MONTH';
 
 140     $spc = $myconfig->{dateformat};
 
 142     $spc = substr($spc, 1, 1);
 
 145       if ($myconfig->{dateformat} =~ /^yy/) {
 
 146         ($yy, $mm, $dd) = split /\D/, $date;
 
 148       if ($myconfig->{dateformat} =~ /^mm/) {
 
 149         ($mm, $dd, $yy) = split /\D/, $date;
 
 151       if ($myconfig->{dateformat} =~ /^dd/) {
 
 152         ($dd, $mm, $yy) = split /\D/, $date;
 
 155       $date = substr($date, 2);
 
 156       ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
 
 161     $yy = ($yy < 70) ? $yy + 2000 : $yy;
 
 162     $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
 
 164     if ($myconfig->{dateformat} =~ /^dd/) {
 
 165       if (defined $longformat && $longformat == 0) {
 
 167         $dd = "0$dd" if ($dd < 10);
 
 168         $mm = "0$mm" if ($mm < 10);
 
 169         $longdate = "$dd$spc$mm$spc$yy";
 
 172         $longdate .= ($spc eq '.') ? ". " : " ";
 
 173         $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
 
 175     } elsif ($myconfig->{dateformat} eq "yyyy-mm-dd") {
 
 177       # Use German syntax with the ISO date style "yyyy-mm-dd" because
 
 178       # Lx-Office is mainly used in Germany or German speaking countries.
 
 179       if (defined $longformat && $longformat == 0) {
 
 181         $dd = "0$dd" if ($dd < 10);
 
 182         $mm = "0$mm" if ($mm < 10);
 
 183         $longdate = "$yy-$mm-$dd";
 
 186         $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
 
 189       if (defined $longformat && $longformat == 0) {
 
 191         $dd = "0$dd" if ($dd < 10);
 
 192         $mm = "0$mm" if ($mm < 10);
 
 193         $longdate = "$mm$spc$dd$spc$yy";
 
 195         $longdate = &text($self, $self->{$longmonth}[$mm]) . " $dd, $yy";
 
 201   $main::lxdebug->leave_sub();
 
 207   $main::lxdebug->enter_sub();
 
 209   my ($self, $myconfig, $date, $longformat) = @_;
 
 212     $main::lxdebug->leave_sub();
 
 217   $spc = $myconfig->{dateformat};
 
 219   $spc = substr($spc, 1, 1);
 
 222     if ($myconfig->{dateformat} =~ /^yy/) {
 
 223       ($yy, $mm, $dd) = split /\D/, $date;
 
 224     } elsif ($myconfig->{dateformat} =~ /^mm/) {
 
 225       ($mm, $dd, $yy) = split /\D/, $date;
 
 226     } elsif ($myconfig->{dateformat} =~ /^dd/) {
 
 227       ($dd, $mm, $yy) = split /\D/, $date;
 
 230     $date = substr($date, 2);
 
 231     ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
 
 236   $yy = ($yy < 70) ? $yy + 2000 : $yy;
 
 237   $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
 
 239   $main::lxdebug->leave_sub();
 
 240   return ($yy, $mm, $dd);
 
 244   $main::lxdebug->enter_sub();
 
 246   my ($self, $myconfig, $date, $output_format, $longformat) = @_;
 
 248   $main::lxdebug->leave_sub() and return "" unless ($date);
 
 250   my ($yy, $mm, $dd) = $self->parse_date($myconfig, $date);
 
 252   $output_format =~ /d+/;
 
 253   substr($output_format, $-[0], $+[0] - $-[0]) =
 
 254     sprintf("%0" . (length($&)) . "d", $dd);
 
 256   $output_format =~ /m+/;
 
 257   substr($output_format, $-[0], $+[0] - $-[0]) =
 
 258     sprintf("%0" . (length($&)) . "d", $mm);
 
 260   $output_format =~ /y+/;
 
 261   if (length($&) == 2) {
 
 262     $yy -= $yy >= 2000 ? 2000 : 1900;
 
 264   substr($output_format, $-[0], $+[0] - $-[0]) =
 
 265     sprintf("%0" . (length($&)) . "d", $yy);
 
 267   $main::lxdebug->leave_sub();
 
 269   return $output_format;