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();
 
  94   my ($self, $text) = @_;
 
  96   if (exists $self->{texts}->{$text}) {
 
  97     return $self->{iconv}->convert($self->{texts}->{$text});
 
 100   return $self->{iconv_english}->convert($text);
 
 104   $main::lxdebug->enter_sub();
 
 106   my ($self, $text) = @_;
 
 108   if (exists $self->{subs}{$text}) {
 
 109     $text = $self->{subs}{$text};
 
 111     if ($self->{countrycode} && $self->{NLS_file}) {
 
 113          "$text not defined in locale/$self->{countrycode}/$self->{NLS_file}");
 
 117   $main::lxdebug->leave_sub();
 
 123   $main::lxdebug->enter_sub();
 
 125   my ($self, $myconfig, $date, $longformat) = @_;
 
 128   my $longmonth = ($longformat) ? 'LONG_MONTH' : 'SHORT_MONTH';
 
 133     $spc = $myconfig->{dateformat};
 
 135     $spc = substr($spc, 1, 1);
 
 138       if ($myconfig->{dateformat} =~ /^yy/) {
 
 139         ($yy, $mm, $dd) = split /\D/, $date;
 
 141       if ($myconfig->{dateformat} =~ /^mm/) {
 
 142         ($mm, $dd, $yy) = split /\D/, $date;
 
 144       if ($myconfig->{dateformat} =~ /^dd/) {
 
 145         ($dd, $mm, $yy) = split /\D/, $date;
 
 148       $date = substr($date, 2);
 
 149       ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
 
 154     $yy = ($yy < 70) ? $yy + 2000 : $yy;
 
 155     $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
 
 157     if ($myconfig->{dateformat} =~ /^dd/) {
 
 158       if (defined $longformat && $longformat == 0) {
 
 160         $dd = "0$dd" if ($dd < 10);
 
 161         $mm = "0$mm" if ($mm < 10);
 
 162         $longdate = "$dd$spc$mm$spc$yy";
 
 165         $longdate .= ($spc eq '.') ? ". " : " ";
 
 166         $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
 
 168     } elsif ($myconfig->{dateformat} eq "yyyy-mm-dd") {
 
 170       # Use German syntax with the ISO date style "yyyy-mm-dd" because
 
 171       # Lx-Office is mainly used in Germany or German speaking countries.
 
 172       if (defined $longformat && $longformat == 0) {
 
 174         $dd = "0$dd" if ($dd < 10);
 
 175         $mm = "0$mm" if ($mm < 10);
 
 176         $longdate = "$yy-$mm-$dd";
 
 179         $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
 
 182       if (defined $longformat && $longformat == 0) {
 
 184         $dd = "0$dd" if ($dd < 10);
 
 185         $mm = "0$mm" if ($mm < 10);
 
 186         $longdate = "$mm$spc$dd$spc$yy";
 
 188         $longdate = &text($self, $self->{$longmonth}[$mm]) . " $dd, $yy";
 
 194   $main::lxdebug->leave_sub();
 
 200   $main::lxdebug->enter_sub();
 
 202   my ($self, $myconfig, $date, $longformat) = @_;
 
 205     $main::lxdebug->leave_sub();
 
 210   $spc = $myconfig->{dateformat};
 
 212   $spc = substr($spc, 1, 1);
 
 215     if ($myconfig->{dateformat} =~ /^yy/) {
 
 216       ($yy, $mm, $dd) = split /\D/, $date;
 
 217     } elsif ($myconfig->{dateformat} =~ /^mm/) {
 
 218       ($mm, $dd, $yy) = split /\D/, $date;
 
 219     } elsif ($myconfig->{dateformat} =~ /^dd/) {
 
 220       ($dd, $mm, $yy) = split /\D/, $date;
 
 223     $date = substr($date, 2);
 
 224     ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
 
 229   $yy = ($yy < 70) ? $yy + 2000 : $yy;
 
 230   $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
 
 232   $main::lxdebug->leave_sub();
 
 233   return ($yy, $mm, $dd);
 
 237   $main::lxdebug->enter_sub();
 
 239   my ($self, $myconfig, $date, $output_format, $longformat) = @_;
 
 241   $main::lxdebug->leave_sub() and return "" unless ($date);
 
 243   my ($yy, $mm, $dd) = $self->parse_date($myconfig, $date);
 
 245   $output_format =~ /d+/;
 
 246   substr($output_format, $-[0], $+[0] - $-[0]) =
 
 247     sprintf("%0" . (length($&)) . "d", $dd);
 
 249   $output_format =~ /m+/;
 
 250   substr($output_format, $-[0], $+[0] - $-[0]) =
 
 251     sprintf("%0" . (length($&)) . "d", $mm);
 
 253   $output_format =~ /y+/;
 
 254   if (length($&) == 2) {
 
 255     $yy -= $yy >= 2000 ? 2000 : 1900;
 
 257   substr($output_format, $-[0], $+[0] - $-[0]) =
 
 258     sprintf("%0" . (length($&)) . "d", $yy);
 
 260   $main::lxdebug->leave_sub();
 
 262   return $output_format;