X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLocale.pm;h=0ddcf04510dd038090f159a322caed0a2babba6d;hb=40534aad33bbf6cfb7f1c32e6fea865ed3dd3d35;hp=1e41344552f1247a2e709421f7c4d7e96a9fbbfa;hpb=dc3cd296e62eb09a16fa694d9b3a7158e4cf63bf;p=kivitendo-erp.git diff --git a/SL/Locale.pm b/SL/Locale.pm index 1e4134455..0ddcf0451 100644 --- a/SL/Locale.pm +++ b/SL/Locale.pm @@ -85,13 +85,14 @@ sub _init { $self->{charset} = Common::DEFAULT_CHARSET; } - $self->_read_special_chars_file($country); - 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->_read_special_chars_file($country); } $self->{NLS_file} = $NLS_file; @@ -105,19 +106,44 @@ sub _init { } sub _handle_markup { - my $self = shift; - my $str = shift; + my $self = shift; + my $str = shift; - if ($str eq "\\n") { - return "\n"; - } elsif ($str eq "\\r") { - return "\r"; - } + my $escaped = 0; + my $new_str = ''; + + for (my $i = 0; $i < length $str; $i++) { + my $char = substr $str, $i, 1; + + if ($escaped) { + if ($char eq 'n') { + $new_str .= "\n"; + + } elsif ($char eq 'r') { + $new_str .= "\r"; + + } elsif ($char eq 's') { + $new_str .= ' '; - $str =~ s/\\x(..)/chr(hex($1))/eg; - $str =~ s/\\(.)/$1/g; + } elsif ($char eq 'x') { + $new_str .= chr(hex(substr($str, $i + 1, 2))); + $i += 2; - return $str; + } else { + $new_str .= $char; + } + + $escaped = 0; + + } elsif ($char eq '\\') { + $escaped = 1; + + } else { + $new_str .= $char; + } + } + + return $new_str; } sub _read_special_chars_file { @@ -141,13 +167,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}; @@ -183,14 +209,12 @@ 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}"); - } + if (exists $self->{subs}{$text_rev}) { + $text = $self->{subs}{$text_rev}; + } elsif ($self->{countrycode} && $self->{NLS_file}) { + Form->error("$text not defined in locale/$self->{countrycode}/$self->{NLS_file}"); } $main::lxdebug->leave_sub();