X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLocale.pm;h=0d2a89517ff6e5f7f50be09431545aa384c9ded1;hb=3ff4ec3b71a043e3802ef21838a0cee6d8535e4e;hp=c182117f9bed08a2e863453ca8f32f75e3487eec;hpb=03ea97647e3fbdea4323f4f2136bdfa87cb15c1b;p=kivitendo-erp.git diff --git a/SL/Locale.pm b/SL/Locale.pm index c182117f9..0d2a89517 100644 --- a/SL/Locale.pm +++ b/SL/Locale.pm @@ -42,19 +42,21 @@ use SL::LXDebug; use SL::Common; use SL::Inifile; +use strict; + sub new { $main::lxdebug->enter_sub(); - my ($type, $country, $NLS_file) = @_; + my ($type, $country) = @_; + + $country ||= $::language; + $country =~ s|.*/||; + $country =~ s|\.||g; my $self = {}; bless $self, $type; - $country =~ s|.*/||; - $country =~ s|\.||g; - $NLS_file =~ s|.*/||; - - $self->_init($country, $NLS_file); + $self->_init($country); $main::lxdebug->leave_sub(); @@ -64,12 +66,13 @@ sub new { sub _init { my $self = shift; my $country = shift; - my $NLS_file = shift; + + $self->{charset} = Common::DEFAULT_CHARSET; + $self->{countrycode} = $country; if ($country && -d "locale/$country") { local *IN; - $self->{countrycode} = $country; - if (open(IN, "<", "locale/$country/$NLS_file")) { + if (open(IN, "<", "locale/$country/all")) { my $code = join("", ); eval($code); close(IN); @@ -80,21 +83,18 @@ sub _init { close IN; chomp $self->{charset}; - - } else { - $self->{charset} = Common::DEFAULT_CHARSET; } + } - $self->_read_special_chars_file($country); + my $db_charset = $main::dbcharset || Common::DEFAULT_CHARSET; - my $db_charset = $main::dbcharset || Common::DEFAULT_CHARSET; + $self->{iconv} = Text::Iconv->new($self->{charset}, $db_charset); + $self->{iconv_reverse} = Text::Iconv->new($db_charset, $self->{charset}); + $self->{iconv_english} = Text::Iconv->new('ASCII', $db_charset); + $self->{iconv_iso8859} = Text::Iconv->new('ISO-8859-15', $db_charset); + $self->{iconv_to_iso8859} = Text::Iconv->new($db_charset, 'ISO-8859-15'); - $self->{iconv} = Text::Iconv->new($self->{charset}, $db_charset); - $self->{iconv_english} = Text::Iconv->new('ASCII', $db_charset); - $self->{iconv_iso8859} = Text::Iconv->new('ISO-8859-15', $db_charset); - } - - $self->{NLS_file} = $NLS_file; + $self->_read_special_chars_file($country); push @{ $self->{LONG_MONTH} }, ("January", "February", "March", "April", @@ -166,13 +166,13 @@ sub _read_special_chars_file { } my $scmap = $self->{special_chars_map}->{$format}; - my $order = $scmap->{order}; + my $order = $self->{iconv}->convert($scmap->{order}); delete $scmap->{order}; foreach my $key (keys %{ $scmap }) { - $scmap->{$key} = $self->_handle_markup($scmap->{$key}); + $scmap->{$key} = $self->_handle_markup($self->{iconv}->convert($scmap->{$key})); - my $new_key = $self->_handle_markup($key); + my $new_key = $self->_handle_markup($self->{iconv}->convert($key)); if ($key ne $new_key) { $scmap->{$new_key} = $scmap->{$key}; @@ -185,8 +185,6 @@ sub _read_special_chars_file { $scmap->{order} = [ map { $self->_handle_markup($_) } split m/\s+/, $order ]; $self->{special_chars_map}->{"${format}-reverse"}->{order} = [ grep { $_ } map { $scmap->{$_} } reverse @{ $scmap->{order} } ]; } - - $main::lxdebug->dump(0, "scm", $self->{special_chars_map}); } sub text { @@ -210,19 +208,27 @@ sub findsub { $main::lxdebug->enter_sub(); my ($self, $text) = @_; + my $text_rev = $self->{iconv_reverse}->convert($text); - if (exists $self->{subs}{$text}) { - $text = $self->{subs}{$text}; - } else { - if ($self->{countrycode} && $self->{NLS_file}) { - Form->error( - "$text not defined in locale/$self->{countrycode}/$self->{NLS_file}"); - } + $self->{subs} ||= { }; + + if (!$self->{subs}->{$text_rev}) { + $self->{texts_reverse} ||= { reverse %{ $self->{texts} } }; + my $sub_name = $self->{texts_reverse}->{$text_rev}; + $sub_name ||= $text_rev if $text_rev =~ m/^[a-z][a-z0-9_]+$/; + + $main::form->error("$text not defined in locale/$self->{countrycode}/all") if !$sub_name; + + $sub_name = lc $sub_name; + $sub_name =~ s/[^a-z0-9]/_/g; + $sub_name =~ s/_+/_/g; + + $self->{subs}->{$text_rev} = $sub_name; } $main::lxdebug->leave_sub(); - return $text; + return $self->{subs}->{$text_rev}; } sub date { @@ -233,6 +239,8 @@ sub date { my $longdate = ""; my $longmonth = ($longformat) ? 'LONG_MONTH' : 'SHORT_MONTH'; + my ($spc, $yy, $mm, $dd); + if ($date) { # get separator @@ -306,6 +314,7 @@ sub parse_date { $main::lxdebug->enter_sub(); my ($self, $myconfig, $date, $longformat) = @_; + my ($spc, $yy, $mm, $dd); unless ($date) { $main::lxdebug->leave_sub(); @@ -357,11 +366,7 @@ sub reformat_date { sprintf("%0" . (length($&)) . "d", $mm); $output_format =~ /y+/; - if (length($&) == 2) { - $yy -= $yy >= 2000 ? 2000 : 1900; - } - substr($output_format, $-[0], $+[0] - $-[0]) = - sprintf("%0" . (length($&)) . "d", $yy); + substr($output_format, $-[0], $+[0] - $-[0]) = $yy; $main::lxdebug->leave_sub();