# file KLEIDER/web/src/localization/Translate.pm # symlink INC/Herbaer/Translate.pm # Übersetzer wählen # 2015-08-03 Herbert Schiemann # 2020-04-03 Platzhalter ${basedir} # GPL Version 2 oder neuer package Herbaer::Translate ; BEGIN { use utf8 ; use Cwd qw(realpath); binmode (STDOUT, ":utf8") ; binmode (STDERR, ":utf8") ; my $n = realpath($0); $n =~ s/\/web\/src\/.*$//; our $basedir = $n; our $namelist = []; my $fn = $INC{"Herbaer/Translate.pm"}; $fn =~ s/\.pm$/.names/ ; my $fh; my $line; my $lnr = 0; my $module; my $modargs = []; if ( open ($fh, "<:encoding(utf-8)", $fn) ) { while (defined ($line = <$fh>)) { ++$lnr; next if $line =~ /^#/ ; $line =~ s/\s*$//; next unless $line; if ( $line =~ s/^MODULE// ) { if ( $line =~ s/^\s+(\S+)// ) { $module = $1; } else { die "Fehler in Datei \"$fn\":\n$line\n"; } $modargs = []; while ( $line =~ s/^\s+(\S+)// ) { push (@$modargs, $1); } } else { $line =~ s/^\s+//; $line =~ s/\s+/ /; if ( $module ) { push (@$namelist, [ qr/$line/, $module, $modargs ]); } else { die "Fehler in Datei \"n$fn\": Modul nicht definiert:\n$line\n"; } } } close $fh; } } # BEGIN use utf8 ; use Herbaer::Replace ; sub new { my $class = shift; my $trans = shift; print STDERR "Herbaer::Translate::new (\"$trans\")\n"; die "Übersetzer nicht angegeben" unless $trans; my $impl = ""; my $p; my $ma; # Argumente aus Translate.names my $i; # Nummer einer Match-Gruppe my $b ; # Beginn einer Match-Gruppe my ($n, $v) ; # Name und Wert einer benannten Match-Gruppe my $repl = { "basedir" => $basedir, }; # Ersetzungs-Hash for $p (@$namelist) { if ($trans =~ $p -> [0]) { $impl = $p -> [1]; $i = 0; for $b (@-) { if ($i) { $repl -> {"$i"} = substr ($trans, $b, $+[$i] - $b) if defined ($b); } ++$i; } while ( ($n, $v) = each (%+) ) { $repl -> {$n} = $v if defined ($v); } $ma = replace ([@{$p -> [2]}], $repl); last; } } if (!$impl) { if ($trans =~ s/\s*(\S+)// ) { $impl = $1; $ma = []; while ( $trans =~ s/\s*(\S+)// ) { push (@$ma, $1); } replace ($ma, $repl); } }; $impl = "Herbaer::Translate::$impl" unless $impl =~ /::/ ; no strict "refs"; # s. perlmod unless (exists ${"$impl\::"}{"new"}) { my $pmfile = "$impl.pm"; $pmfile =~ s/::/\//g; eval { require $pmfile } ; die $@ if $@; } return $impl -> new (@$ma, @_); } # new 1; # end of file KLEIDER/web/src/localization/Translate.pm