get_vendor war nicht hinreichend abgesichert gegen mehrfache aufrufe.
[kivitendo-erp.git] / SL / Locale.pm
index c182117..0b535d7 100644 (file)
@@ -85,13 +85,15 @@ sub _init {
       $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->_read_special_chars_file($country);
   }
 
   $self->{NLS_file} = $NLS_file;
@@ -166,13 +168,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 +187,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,14 +210,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();