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) = @_;
 
  50   if ($country && -d "locale/$country") {
 
  52     $self->{countrycode} = $country;
 
  53     if (open(IN, "locale/$country/$NLS_file")) {
 
  54       my $code = join("", <IN>);
 
  59     if (open IN, "<", "locale/$country/charset") {
 
  60       $self->{charset} = <IN>;
 
  63       chomp $self->{charset};
 
  66       $self->{charset} = Common::DEFAULT_CHARSET;
 
  69     my $db_charset = $main::dbcharset;
 
  70     $db_charset ||= Common::DEFAULT_CHARSET;
 
  71     $self->{iconv} = Text::Iconv->new($self->{charset}, $db_charset);
 
  72     $self->{iconv_english} = Text::Iconv->new("ASCII", $db_charset);
 
  75   $self->{NLS_file} = $NLS_file;
 
  77   push @{ $self->{LONG_MONTH} },
 
  78     ("January",   "February", "March",    "April",
 
  79      "May ",      "June",     "July",     "August",
 
  80      "September", "October",  "November", "December");
 
  81   push @{ $self->{SHORT_MONTH} },
 
  82     (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
 
  84   $main::lxdebug->leave_sub();
 
  90   my ($self, $text) = @_;
 
  92   if (exists $self->{texts}->{$text}) {
 
  93     return $self->{iconv}->convert($self->{texts}->{$text});
 
  96   return $self->{iconv_english}->convert($text);
 
 100   $main::lxdebug->enter_sub();
 
 102   my ($self, $text) = @_;
 
 104   if (exists $self->{subs}{$text}) {
 
 105     $text = $self->{subs}{$text};
 
 107     if ($self->{countrycode} && $self->{NLS_file}) {
 
 109          "$text not defined in locale/$self->{countrycode}/$self->{NLS_file}");
 
 113   $main::lxdebug->leave_sub();
 
 119   $main::lxdebug->enter_sub();
 
 121   my ($self, $myconfig, $date, $longformat) = @_;
 
 124   my $longmonth = ($longformat) ? 'LONG_MONTH' : 'SHORT_MONTH';
 
 129     $spc = $myconfig->{dateformat};
 
 131     $spc = substr($spc, 1, 1);
 
 134       if ($myconfig->{dateformat} =~ /^yy/) {
 
 135         ($yy, $mm, $dd) = split /\D/, $date;
 
 137       if ($myconfig->{dateformat} =~ /^mm/) {
 
 138         ($mm, $dd, $yy) = split /\D/, $date;
 
 140       if ($myconfig->{dateformat} =~ /^dd/) {
 
 141         ($dd, $mm, $yy) = split /\D/, $date;
 
 144       $date = substr($date, 2);
 
 145       ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
 
 150     $yy = ($yy < 70) ? $yy + 2000 : $yy;
 
 151     $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
 
 153     if ($myconfig->{dateformat} =~ /^dd/) {
 
 154       if (defined $longformat && $longformat == 0) {
 
 156         $dd = "0$dd" if ($dd < 10);
 
 157         $mm = "0$mm" if ($mm < 10);
 
 158         $longdate = "$dd$spc$mm$spc$yy";
 
 161         $longdate .= ($spc eq '.') ? ". " : " ";
 
 162         $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
 
 164     } elsif ($myconfig->{dateformat} eq "yyyy-mm-dd") {
 
 166       # Use German syntax with the ISO date style "yyyy-mm-dd" because
 
 167       # Lx-Office is mainly used in Germany or German speaking countries.
 
 168       if (defined $longformat && $longformat == 0) {
 
 170         $dd = "0$dd" if ($dd < 10);
 
 171         $mm = "0$mm" if ($mm < 10);
 
 172         $longdate = "$yy-$mm-$dd";
 
 175         $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
 
 178       if (defined $longformat && $longformat == 0) {
 
 180         $dd = "0$dd" if ($dd < 10);
 
 181         $mm = "0$mm" if ($mm < 10);
 
 182         $longdate = "$mm$spc$dd$spc$yy";
 
 184         $longdate = &text($self, $self->{$longmonth}[$mm]) . " $dd, $yy";
 
 190   $main::lxdebug->leave_sub();
 
 196   $main::lxdebug->enter_sub();
 
 198   my ($self, $myconfig, $date, $longformat) = @_;
 
 201     $main::lxdebug->leave_sub();
 
 206   $spc = $myconfig->{dateformat};
 
 208   $spc = substr($spc, 1, 1);
 
 211     if ($myconfig->{dateformat} =~ /^yy/) {
 
 212       ($yy, $mm, $dd) = split /\D/, $date;
 
 213     } elsif ($myconfig->{dateformat} =~ /^mm/) {
 
 214       ($mm, $dd, $yy) = split /\D/, $date;
 
 215     } elsif ($myconfig->{dateformat} =~ /^dd/) {
 
 216       ($dd, $mm, $yy) = split /\D/, $date;
 
 219     $date = substr($date, 2);
 
 220     ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
 
 225   $yy = ($yy < 70) ? $yy + 2000 : $yy;
 
 226   $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
 
 228   $main::lxdebug->leave_sub();
 
 229   return ($yy, $mm, $dd);
 
 233   $main::lxdebug->enter_sub();
 
 235   my ($self, $myconfig, $date, $output_format, $longformat) = @_;
 
 237   $main::lxdebug->leave_sub() and return "" unless ($date);
 
 239   my ($yy, $mm, $dd) = $self->parse_date($myconfig, $date);
 
 241   $output_format =~ /d+/;
 
 242   substr($output_format, $-[0], $+[0] - $-[0]) =
 
 243     sprintf("%0" . (length($&)) . "d", $dd);
 
 245   $output_format =~ /m+/;
 
 246   substr($output_format, $-[0], $+[0] - $-[0]) =
 
 247     sprintf("%0" . (length($&)) . "d", $mm);
 
 249   $output_format =~ /y+/;
 
 250   if (length($&) == 2) {
 
 251     $yy -= $yy >= 2000 ? 2000 : 1900;
 
 253   substr($output_format, $-[0], $+[0] - $-[0]) =
 
 254     sprintf("%0" . (length($&)) . "d", $yy);
 
 256   $main::lxdebug->leave_sub();
 
 258   return $output_format;