Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 77919bac

Von Sven Schöling vor etwa 14 Jahren hinzugefügt

  • ID 77919bac9e5a5334630b727eef82098b5dea1676
  • Vorgänger b61f5c3d
  • Nachfolger 79038417

Anpassung locales.pl an neue Situation ohne explizit übersetzte Templates

Conflicts:

locale/de/all

Zusätzlich einige Templates angepasst, die in den vorherigen Sweeps nicht
mit eingecheckt wurden.

Unterschiede anzeigen:

locale/de/locales.pl
105 105

  
106 106
my %old_texts = %{ $self->{texts} || {} };
107 107

  
108
# Read HTML templates.
109
#%htmllocale = ();
110
#@htmltemplates = <../../templates/webpages/*/*_master.html>;
111
#foreach $file (@htmltemplates) {
112
#  scanhtmlfile($file);
113
#}
114

  
115 108
map({ handle_file($_, $bindir); } @progfiles);
116 109
map({ handle_file($_, $dbupdir); } @dbplfiles);
117 110
map({ handle_file($_, $dbupdir2); } @dbplfiles2);
......
218 211

  
219 212
}
220 213

  
221
#foreach $file (@htmltemplates) {
222
#  converthtmlfile($file);
223
#}
224

  
225 214
# now print out all
226 215

  
227 216
open FH, ">all" or die "$! : all";
......
318 307

  
319 308
if ($opt_c) {
320 309
  search_unused_htmlfiles();
321
  search_translated_htmlfiles_wo_master();
322 310
}
323 311

  
324 312
my $per = sprintf("%.1f", ($count - $notext) / $count * 100);
......
421 409

  
422 410
      # is this a template call?
423 411
      if (/parse_html_template2?\s*\(\s*[\"\']([\w\/]+)\s*[\"\']/) {
424
        my $newfile = "$basedir/templates/webpages/$1_master.html";
412
        my $newfile = "$basedir/templates/webpages/$1.html";
425 413
        if (/parse_html_template2/) {
426 414
          print "E: " . strip_base($file) . " is still using 'parse_html_template2' for " . strip_base($newfile) . ".\n";
427 415
        }
428 416
        if (-f $newfile) {
429 417
#           &scanhtmlfile($newfile);
430
#           &converthtmlfile($newfile);
431 418
           $cached{$file}{scanh}{$newfile} = 1;
432 419
          print "." if $opt_v;
433 420
        } elsif ($opt_c) {
......
543 530

  
544 531
}
545 532

  
533
sub unescape_template_string {
534
  my $in      = shift;
535
  my $out     = '';
536
  my $escaped = 0;
537

  
538
  foreach my $char (split m//, $in) {
539
    if ($escaped) {
540
      $out     .= $char;
541
      $escaped  = 0;
542
    } elsif ($char eq '\\') {
543
      $escaped  = 1;
544
    } else {
545
      $out     .= $char;
546
    }
547
  }
548

  
549
  return $out;
550
}
551

  
546 552
sub scanhtmlfile {
547 553
  local *IN;
548 554

  
549
  if (!defined $cached{$_[0]}) {
555
  my $file = shift;
556

  
557
  if (!defined $cached{$file}) {
550 558
    my %plugins = ( 'loaded' => { }, 'needed' => { } );
551 559

  
552
    open(IN, $_[0]) || die $_[0];
560
    open(IN, $file) || die $file;
553 561

  
554 562
    my $copying  = 0;
555 563
    my $issubmit = 0;
......
567 575
      }
568 576

  
569 577
      while ($line =~ m/(?:             # Start von Variante 1: LxERP.t8('...'); ohne darumliegende [% ... %]-Tags
570
                          (LxERP\.t8)\( #   LxERP.t8(
571
                          [\'\"]        #   Anfang des zu ?bersetzenden Strings
572
                          (.*?)         #   Der zu ?bersetzende String
573
                          [\'\"]        #   Ende des zu ?bersetzenden Strings
578
                          (LxERP\.t8)\( #   LxERP.t8(                             ::Parameter $1::
579
                          ([\'\"])      #   Anfang des zu ?bersetzenden Strings   ::Parameter $2::
580
                          (.*?)         #   Der zu ?bersetzende String            ::Parameter $3::
581
                          (?<!\\)\2     #   Ende des zu ?bersetzenden Strings
574 582
                        |               # Start von Variante 2: [% '...' | $T8 %]
575 583
                          \[\%          #   Template-Start-Tag
576 584
                          [\-~#]*       #   Whitespace-Unterdr?ckung
577 585
                          \s*           #   Optional beliebig viele Whitespace
578
                          [\'\"]        #   Anfang des zu ?bersetzenden Strings
579
                          (.*?)         #   Der zu ?bersetzende String
580
                          [\'\"]        #   Ende des zu ?bersetzenden Strings
586
                          ([\'\"])      #   Anfang des zu ?bersetzenden Strings   ::Parameter $4::
587
                          (.*?)         #   Der zu ?bersetzende String            ::Parameter $5::
588
                          (?<!\\)\4     #   Ende des zu ?bersetzenden Strings
581 589
                          \s*\|\s*      #   Pipe-Zeichen mit optionalen Whitespace davor und danach
582
                          (\$T8)        #   Filteraufruf
590
                          (\$T8)        #   Filteraufruf                          ::Parameter $6::
583 591
                          .*?           #   Optionale Argumente f?r den Filter
584 592
                          \s*           #   Whitespaces
585 593
                          [\-~#]*       #   Whitespace-Unterdr?ckung
586 594
                          \%\]          #   Template-Ende-Tag
587 595
                        )
588 596
                       /ix) {
589
        my $module = $1 || $4;
590
        my $string = $2 || $3;
597
        my $module = $1 || $6;
598
        my $string = $3 || $5;
591 599
        print "Found filter >>>$string<<<\n" if $debug;
592 600
        substr $line, $LAST_MATCH_START[1], $LAST_MATCH_END[0] - $LAST_MATCH_START[0], '';
593 601

  
594
        $cached{$_[0]}{all}{$string}    = 1;
595
        $cached{$_[0]}{html}{$string}   = 1;
596
        $cached{$_[0]}{submit}{$string} = 1 if $PREMATCH =~ /$submitsearch/;
602
        $string                         = unescape_template_string($string);
603
        $cached{$file}{all}{$string}    = 1;
604
        $cached{$file}{html}{$string}   = 1;
605
        $cached{$file}{submit}{$string} = 1 if $PREMATCH =~ /$submitsearch/;
597 606
        $plugins{needed}->{T8}          = 1 if $module eq '$T8';
607
        $plugins{needed}->{LxERP}       = 1 if $module eq 'LxERP.t8';
598 608
      }
599 609

  
600
      while ("" ne $line) {
601
        if (!$copying) {
602
          if ($line =~ m|<translate>|i) {
603
            my $eom = $+[0];
604
            if ($` =~ /$submitsearch/) {
605
              $issubmit = 1
606
            }
607
            substr($line, 0, $eom) = "";
608
            $copying = 1;
609
          } else {
610
            $line = "";
611
          }
612

  
613
        } else {
614
          if ($line =~ m|</translate>|i) {
615
            $text .= $`;
616
            substr($line, 0, $+[0]) = "";
617
            $text =~ s/\s+/ /g;
618

  
619
            $copying = 0;
620
            if ($issubmit) {
621
  #            $submit{$text} = 1;
622
               $cached{$_[0]}{submit}{$text} = 1;
623
              $issubmit = 0;
624
            }
625
  #          $alllocales{$text} = 1;
626
             $cached{$_[0]}{all}{$text} = 1;
627
  #          $htmllocale{$text} = 1;
628
             $cached{$_[0]}{html}{$text} = 1;
629
            $text = "";
630

  
631
          } else {
632
            $text .= $line;
633
            $line = "";
634
          }
635
        }
610
      while ($line =~ m/\[\%          # Template-Start-Tag
611
                        [\-~#]?       # Whitespace-Unterdr?ckung
612
                        \s*           # Optional beliebig viele Whitespace
613
                        (?:           # Die erkannten Template-Direktiven
614
                          PROCESS
615
                        |
616
                          INCLUDE
617
                        )
618
                        \s+           # Mindestens ein Whitespace
619
                        [\'\"]?       # Anfang des Dateinamens
620
                        ([^\s]+)      # Beliebig viele Nicht-Whitespaces -- Dateiname
621
                        \.html        # Endung ".html", ansonsten kann es der Name eines Blocks sein
622
                       /ix) {
623
        my $new_file_name = "$basedir/templates/webpages/$1.html";
624
        $cached{$file}{scanh}{$new_file_name} = 1;
625
        substr $line, $LAST_MATCH_START[1], $LAST_MATCH_END[0] - $LAST_MATCH_START[0], '';
636 626
      }
637 627
    }
638 628

  
......
640 630

  
641 631
    foreach my $plugin (keys %{ $plugins{needed} }) {
642 632
      next if ($plugins{loaded}->{$plugin});
643
      print "E: " . strip_base($_[0]) . " requires the Template plugin '$plugin', but is not loaded with '[\% USE $plugin \%]'.\n";
633
      print "E: " . strip_base($file) . " requires the Template plugin '$plugin', but is not loaded with '[\% USE $plugin \%]'.\n";
644 634
    }
645

  
646
    &converthtmlfile($_[0]);
647 635
  }
648 636

  
649 637
  # copy back into global arrays
650
  map { $alllocales{$_} = 1 } keys %{$cached{$_[0]}{all}};
651
  map { $htmllocale{$_} = 1 } keys %{$cached{$_[0]}{html}};
652
  map { $submit{$_} = 1 }     keys %{$cached{$_[0]}{submit}};
653
}
654

  
655
sub converthtmlfile {
656
  local *IN;
657
  local *OUT;
658

  
659
  my $file = shift;
660

  
661
  open(IN, $file) || die;
638
  map { $alllocales{$_} = 1 } keys %{$cached{$file}{all}};
639
  map { $htmllocale{$_} = 1 } keys %{$cached{$file}{html}};
640
  map { $submit{$_} = 1 }     keys %{$cached{$file}{submit}};
662 641

  
663
  my $langcode = (split("/", getcwd()))[-1];
664
  $file =~ s/_master.html$/_${langcode}.html/;
642
  map { scanhtmlfile($_)  }   keys %{$cached{$file}{scanh}};
665 643

  
666
  open(OUT, ">$file") || die;
667

  
668
  my $copying = 0;
669
  my $text = "";
670
  while (my $line = <IN>) {
671
    chomp($line);
672
    if ("" eq $line) {
673
      print(OUT "\n");
674
      next;
675
    }
676

  
677
    while ("" ne $line) {
678
      if (!$copying) {
679
        if ($line =~ m|<translate>|i) {
680
          print(OUT $`);
681
          substr($line, 0, $+[0]) = "";
682
          $copying = 1;
683
          print(OUT "\n") if ("" eq $line);
684

  
685
        } else {
686
          print(OUT "${line}\n");
687
          $line = "";
688
        }
689

  
690
      } else {
691
        if ($line =~ m|</translate>|i) {
692
          $text .= $`;
693
          substr($line, 0, $+[0]) = "";
694
          $text =~ s/\s+/ /g;
695
          $copying = 0;
696
          $alllocales{$text} = 1;
697
          $htmllocale{$text} = 1;
698
          print(OUT $self->{"texts"}{$text} || $text);
699
          print(OUT "\n") if ("" eq $line);
700
          $text = "";
701

  
702
        } else {
703
          $text .= $line;
704
          $line = "";
705
        }
706
      }
707
    }
708
  }
709

  
710
  close(IN);
711
  close(OUT);
644
  @referenced_html_files{keys %{$cached{$file}{scanh}}} = (1) x scalar keys %{$cached{$file}{scanh}};
712 645
}
713 646

  
714 647
sub search_unused_htmlfiles {
......
729 662
  }
730 663
}
731 664

  
732
sub search_translated_htmlfiles_wo_master {
733
  my @unscanned_dirs = ('../../templates/webpages');
734

  
735
  while (scalar @unscanned_dirs) {
736
    my $dir = shift @unscanned_dirs;
737

  
738
    foreach my $entry (<$dir/*>) {
739
      if (-d $entry) {
740
        push @unscanned_dirs, $entry;
741

  
742
      } elsif (($entry =~ /_[a-z]+\.html$/) && ($entry !~ /_master.html$/) && -f $entry) {
743
        my $master =  $entry;
744
        $master    =~ s/[a-z]+\.html$/master.html/;
745
        if (! -f $master) {
746
          print "W: translated HTML template without master: " . strip_base($entry) . "\n";
747
        }
748
      }
749
    }
750
  }
751
}
752

  
753 665
sub strip_base {
754 666
  my $s =  "$_[0]";             # Create a copy of the string.
755 667

  

Auch abrufbar als: Unified diff