Revision 1682d89d
Von Moritz Bunkus vor mehr als 14 Jahren hinzugefügt
SL/Locale.pm | ||
---|---|---|
47 | 47 |
sub new { |
48 | 48 |
$main::lxdebug->enter_sub(); |
49 | 49 |
|
50 |
my ($type, $country, $NLS_file) = @_; |
|
50 |
my ($type, $country) = @_; |
|
51 |
|
|
52 |
$country ||= $::language; |
|
53 |
$country =~ s|.*/||; |
|
54 |
$country =~ s|\.||g; |
|
51 | 55 |
|
52 | 56 |
my $self = {}; |
53 | 57 |
bless $self, $type; |
54 | 58 |
|
55 |
$country =~ s|.*/||; |
|
56 |
$country =~ s|\.||g; |
|
57 |
$NLS_file =~ s|.*/||; |
|
58 |
|
|
59 |
$self->_init($country, $NLS_file); |
|
59 |
$self->_init($country); |
|
60 | 60 |
|
61 | 61 |
$main::lxdebug->leave_sub(); |
62 | 62 |
|
... | ... | |
66 | 66 |
sub _init { |
67 | 67 |
my $self = shift; |
68 | 68 |
my $country = shift; |
69 |
my $NLS_file = shift; |
|
70 | 69 |
|
71 | 70 |
$self->{charset} = Common::DEFAULT_CHARSET; |
72 | 71 |
$self->{countrycode} = $country; |
73 |
$self->{NLS_file} = $NLS_file; |
|
74 | 72 |
|
75 | 73 |
if ($country && -d "locale/$country") { |
76 | 74 |
local *IN; |
77 |
if (open(IN, "<", "locale/$country/$NLS_file")) {
|
|
75 |
if (open(IN, "<", "locale/$country/all")) {
|
|
78 | 76 |
my $code = join("", <IN>); |
79 | 77 |
eval($code); |
80 | 78 |
close(IN); |
... | ... | |
212 | 210 |
my ($self, $text) = @_; |
213 | 211 |
my $text_rev = $self->{iconv_reverse}->convert($text); |
214 | 212 |
|
215 |
if (exists $self->{subs}{$text_rev}) { |
|
216 |
$text = $self->{subs}{$text_rev}; |
|
217 |
} elsif ($self->{countrycode} && $self->{NLS_file}) { |
|
218 |
$main::form->error("$text not defined in locale/$self->{countrycode}/$self->{NLS_file}"); |
|
213 |
$self->{subs} ||= { }; |
|
214 |
|
|
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_]+$/; |
|
219 |
|
|
220 |
$main::form->error("$text not defined in locale/$self->{countrycode}/all") if !$sub_name; |
|
221 |
|
|
222 |
$sub_name = lc $sub_name; |
|
223 |
$sub_name =~ s/[^a-z0-9]/_/g; |
|
224 |
$sub_name =~ s/_+/_/g; |
|
225 |
|
|
226 |
$self->{subs}->{$text_rev} = $sub_name; |
|
219 | 227 |
} |
220 | 228 |
|
221 | 229 |
$main::lxdebug->leave_sub(); |
222 | 230 |
|
223 |
return $text;
|
|
231 |
return $self->{subs}->{$text_rev};
|
|
224 | 232 |
} |
225 | 233 |
|
226 | 234 |
sub date { |
Auch abrufbar als: Unified diff
Locale benutzt nur noch locale/de/all
Die Funktionsnamensauflösung wird nun bei jedem Aufruf von Locale
selber durchgeführt.