From 5367525b274785435844298fcf299cdd4d1ac2bd Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 1 Feb 2010 14:21:52 +0100 Subject: [PATCH] =?utf8?q?Funktionsnamensaufl=C3=B6sung=20gefixt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- SL/Locale.pm | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) 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 { -- 2.20.1