Revision 5367525b
Von Moritz Bunkus vor mehr als 14 Jahren hinzugefügt
SL/Locale.pm | ||
---|---|---|
37 | 37 |
package Locale; |
38 | 38 |
|
39 | 39 |
use Text::Iconv; |
40 |
use List::Util qw(first); |
|
40 | 41 |
|
41 | 42 |
use SL::LXDebug; |
42 | 43 |
use SL::Common; |
... | ... | |
208 | 209 |
$main::lxdebug->enter_sub(); |
209 | 210 |
|
210 | 211 |
my ($self, $text) = @_; |
211 |
my $text_rev = $self->{iconv_reverse}->convert($text); |
|
212 |
my $text_rev = lc $self->{iconv_reverse}->convert($text);
|
|
212 | 213 |
|
213 |
$self->{subs} ||= { }; |
|
214 |
if (!$self->{texts_reverse}) { |
|
215 |
$self->{texts_reverse} = { }; |
|
216 |
while (my ($original, $translation) = each %{ $self->{texts} }) { |
|
217 |
$original = lc $original; |
|
218 |
$original =~ s/[^a-z0-9]/_/g; |
|
219 |
$original =~ s/_+/_/g; |
|
214 | 220 |
|
215 |
if (!$self->{subs}->{$text_rev}) { |
|
216 |
$self->{texts_reverse} ||= { reverse %{ $self->{texts} } }; |
|
217 |
my $sub_name = $self->{texts_reverse}->{$text_rev}; |
|
218 |
$sub_name ||= $text_rev if $text_rev =~ m/^[a-z][a-z0-9_]+$/; |
|
221 |
$translation = lc $translation; |
|
219 | 222 |
|
220 |
$main::form->error("$text not defined in locale/$self->{countrycode}/all") if !$sub_name; |
|
223 |
$self->{texts_reverse}->{$translation} ||= [ ]; |
|
224 |
push @{ $self->{texts_reverse}->{$translation} }, $original; |
|
225 |
} |
|
226 |
} |
|
221 | 227 |
|
222 |
$sub_name = lc $sub_name; |
|
223 |
$sub_name =~ s/[^a-z0-9]/_/g; |
|
224 |
$sub_name =~ s/_+/_/g; |
|
228 |
my $sub_name = first { defined &{ "::$_" } } @{ $self->{texts_reverse}->{$text_rev} } if $self->{texts_reverse}->{$text_rev}; |
|
229 |
$sub_name ||= $text_rev if ($text_rev =~ m/^[a-z][a-z0-9_]+$/) && defined &{ "::$text_rev" }; |
|
225 | 230 |
|
226 |
$self->{subs}->{$text_rev} = $sub_name; |
|
227 |
} |
|
231 |
$main::form->error("$text not defined in locale/$self->{countrycode}/all") if !$sub_name; |
|
228 | 232 |
|
229 | 233 |
$main::lxdebug->leave_sub(); |
230 | 234 |
|
231 |
return $self->{subs}->{$text_rev};
|
|
235 |
return $sub_name;
|
|
232 | 236 |
} |
233 | 237 |
|
234 | 238 |
sub date { |
Auch abrufbar als: Unified diff
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.