From: Moritz Bunkus Date: Mon, 1 Feb 2010 13:21:52 +0000 (+0100) Subject: Funktionsnamensauflösung gefixt X-Git-Tag: release-2.6.2beta1~254 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=5367525b274785435844298fcf299cdd4d1ac2bd;p=kivitendo-erp.git Funktionsnamensauflösung gefixt Nicht einfach nur die Übersetzungstabelle umdrehen, weil es mehrere Originalbegriffe mit derselben Übersetzung gibt. Also zur Laufzeit überprüfen, welcher der Originalbegriffe als Funktionsname in dem Moment des Aufrufes in Frage kommt, sprich welche Funktion in 'main::' in dem Moment definiert ist. --- diff --git a/SL/Locale.pm b/SL/Locale.pm index 0d2a89517..05f55ce46 100644 --- a/SL/Locale.pm +++ b/SL/Locale.pm @@ -37,6 +37,7 @@ package Locale; use Text::Iconv; +use List::Util qw(first); use SL::LXDebug; use SL::Common; @@ -208,27 +209,30 @@ sub findsub { $main::lxdebug->enter_sub(); my ($self, $text) = @_; - my $text_rev = $self->{iconv_reverse}->convert($text); + my $text_rev = lc $self->{iconv_reverse}->convert($text); - $self->{subs} ||= { }; + if (!$self->{texts_reverse}) { + $self->{texts_reverse} = { }; + while (my ($original, $translation) = each %{ $self->{texts} }) { + $original = lc $original; + $original =~ s/[^a-z0-9]/_/g; + $original =~ s/_+/_/g; - 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_]+$/; + $translation = lc $translation; - $main::form->error("$text not defined in locale/$self->{countrycode}/all") if !$sub_name; + $self->{texts_reverse}->{$translation} ||= [ ]; + push @{ $self->{texts_reverse}->{$translation} }, $original; + } + } - $sub_name = lc $sub_name; - $sub_name =~ s/[^a-z0-9]/_/g; - $sub_name =~ s/_+/_/g; + my $sub_name = first { defined &{ "::$_" } } @{ $self->{texts_reverse}->{$text_rev} } if $self->{texts_reverse}->{$text_rev}; + $sub_name ||= $text_rev if ($text_rev =~ m/^[a-z][a-z0-9_]+$/) && defined &{ "::$text_rev" }; - $self->{subs}->{$text_rev} = $sub_name; - } + $main::form->error("$text not defined in locale/$self->{countrycode}/all") if !$sub_name; $main::lxdebug->leave_sub(); - return $self->{subs}->{$text_rev}; + return $sub_name; } sub date {