Przeglądaj źródła

Generate stats in multiple languages in a single run.

Christoph Berg 21 lat temu
rodzic
commit
cba247a44b
5 zmienionych plików z 50 dodań i 29 usunięć
  1. 1 1
      docs/CREDITS
  2. 4 0
      docs/Changelog
  3. 5 2
      docs/pisg-doc.xml
  4. 26 14
      modules/Pisg.pm
  5. 14 12
      modules/Pisg/HTMLGenerator.pm

+ 1 - 1
docs/CREDITS

@@ -111,7 +111,7 @@ Other contributors:
    | pisg(1) manpage
    | pisg(1) manpage
  * Torbjörn Svensson <azoff@se.linux.org>
  * Torbjörn Svensson <azoff@se.linux.org>
    | ShowFoulDecimals and AltColorScheme options, multiple channels with same
    | ShowFoulDecimals and AltColorScheme options, multiple channels with same
-   | name, lots of other fixes, pum.pl
+   | name, multiple languages per run, lots of other fixes, pum.pl
  * coaster
  * coaster
    | improved mirc6hack.mrc
    | improved mirc6hack.mrc
  * Vianney Lecroart <acemtp@free.fr>
  * Vianney Lecroart <acemtp@free.fr>

+ 4 - 0
docs/Changelog

@@ -1,3 +1,7 @@
+pisg (0.68) - ??
+   Torbjörn:
+     + Generate stats in multiple languages in a single run.
+
 pisg (0.67) - Thu Aug, 18th 2005
 pisg (0.67) - Thu Aug, 18th 2005
    Christoph:
    Christoph:
      + Recognize ogg and wma suffixes in song stats, complain about invalid
      + Recognize ogg and wma suffixes in song stats, complain about invalid

+ 5 - 2
docs/pisg-doc.xml

@@ -815,9 +815,10 @@
          Logfile = "channel.log"
          Logfile = "channel.log"
          Format = "mIRC"
          Format = "mIRC"
          Lang = "DE"
          Lang = "DE"
+         OutputFile = "mychan-%l.html"
         </channel>
         </channel>
 
 
-        <set Lang="FR">
+        <set Lang="FR,SE">
       ]]>
       ]]>
     </programlisting></refsynopsisdiv>
     </programlisting></refsynopsisdiv>
 
 
@@ -855,7 +856,9 @@
     SQ    (Albanian),
     SQ    (Albanian),
     TR    (Turkish),
     TR    (Turkish),
     YU    (Serbian).
     YU    (Serbian).
-    See also <xref linkend="LangFile" />.
+    Output in several languages can be generated at the same time, separate the
+    languages by comma. The tag %l in the output file name will be replaced by
+    the language name. See also <xref linkend="LangFile" />.
     </para>
     </para>
     </refsect1>
     </refsect1>
     <refsect1>
     <refsect1>

+ 26 - 14
modules/Pisg.pm

@@ -103,7 +103,7 @@ sub get_default_config_settings
         defaultpic => '',
         defaultpic => '',
         logdir => [],
         logdir => [],
         nfiles => 0,
         nfiles => 0,
-        lang => 'EN',
+        langlist => [qw/EN/],
         langfile => 'lang.txt',
         langfile => 'lang.txt',
         cssdir => 'layout/',
         cssdir => 'layout/',
         colorscheme => 'default',
         colorscheme => 'default',
@@ -342,13 +342,20 @@ sub init_config
 
 
             while ($settings =~ s/[ \t]([^=]+?)=(["'])(.*?)\2//) {
             while ($settings =~ s/[ \t]([^=]+?)=(["'])(.*?)\2//) {
                 my $var = lc($1);
                 my $var = lc($1);
+                my $val = $3;
                 $var =~ s/ //; # Remove whitespace
                 $var =~ s/ //; # Remove whitespace
                 if (!defined($self->{cfg}->{$var})) {
                 if (!defined($self->{cfg}->{$var})) {
                     print STDERR "Warning: $self->{cfg}->{configfile}, line $.: No such configuration option: '$var'\n";
                     print STDERR "Warning: $self->{cfg}->{configfile}, line $.: No such configuration option: '$var'\n";
                     next;
                     next;
                 }
                 }
-                unless (($self->{cfg}->{$var} eq $3) || $self->{override_cfg}->{$var}) {
-                    $self->{cfg}->{$var} = $3;
+
+                if ($var eq "lang") {
+                    @{ $self->{cfg}->{langlist} } = split /\s*,\s*/, uc $val;
+                    next;
+                }
+
+                unless (($self->{cfg}->{$var} eq $val) || $self->{override_cfg}->{$var}) {
+                    $self->{cfg}->{$var} = $val;
                 }
                 }
             }
             }
 
 
@@ -358,10 +365,13 @@ sub init_config
             $self->{cfg}->{chan_done}{$self->{cfg}->{channel}} = 1; # don't parse channel in $self->{cfg}->{channel} if a channel statement is present
             $self->{cfg}->{chan_done}{$self->{cfg}->{channel}} = 1; # don't parse channel in $self->{cfg}->{channel} if a channel statement is present
             while ($settings =~ s/\s([^=]+)=(["'])(.+?)\2//) {
             while ($settings =~ s/\s([^=]+)=(["'])(.+?)\2//) {
                 my $var = lc($1);
                 my $var = lc($1);
+                my $val = $3;
                 if ($var eq "logdir" || $var eq "logfile") {
                 if ($var eq "logdir" || $var eq "logfile") {
-                    push(@{$tmp->{$channel}{$var}}, $3);
+                    push(@{$tmp->{$channel}{$var}}, $val);
+                } elsif ($var eq "lang") {
+                    @{ $self->{cfg}->{langlist} } = split /\s*,\s*/, uc $val;
                 } else {
                 } else {
-                    $tmp->{$channel}{$var} = $3;
+                    $tmp->{$channel}{$var} = $val;
                 }
                 }
             }
             }
             while (<$fh>) {
             while (<$fh>) {
@@ -372,12 +382,16 @@ sub init_config
                 }
                 }
                 if ($_ =~ /^\s*(\w+)\s*=\s*(["'])(.+?)\2/) {
                 if ($_ =~ /^\s*(\w+)\s*=\s*(["'])(.+?)\2/) {
                     my $var = lc($1);
                     my $var = lc($1);
+                    my $val = $3;
                     unless ((($var eq "logdir" || $var eq "logfile") && scalar(@{$self->{override_cfg}->{$var}}) > 0) || (($var ne "logdir" && $var ne "logfile") && $self->{override_cfg}->{$var})) {
                     unless ((($var eq "logdir" || $var eq "logfile") && scalar(@{$self->{override_cfg}->{$var}}) > 0) || (($var ne "logdir" && $var ne "logfile") && $self->{override_cfg}->{$var})) {
 
 
                         if($var eq "logdir" || $var eq "logfile") {
                         if($var eq "logdir" || $var eq "logfile") {
-                            push @{$tmp->{$channel}{$var}}, $3;
+                            push @{$tmp->{$channel}{$var}}, $val;
+                        } elsif ($var eq "lang") {
+                            @{ $self->{cfg}->{langlist} } = split /\s*,\s*/, uc $val;
+                            next;
                         } else {
                         } else {
-                            $tmp->{$channel}{$var} = $3;
+                            $tmp->{$channel}{$var} = $val;
                         }
                         }
 
 
                     }
                     }
@@ -427,9 +441,6 @@ sub init_pisg
     }
     }
     $self->{cfg}->{timestamp} = $timestamp;
     $self->{cfg}->{timestamp} = $timestamp;
 
 
-    $self->{cfg}->{lang} = uc $self->{cfg}->{lang};
-    $self->{cfg}->{lang} =~ s/-/_/g; # PT_BR was called PT-BR before
-
     # convert wordlists
     # convert wordlists
     $self->{cfg}->{foulwords} = wordlist_regexp($self->{cfg}->{foulwords}, $self->{cfg}->{regexpaliases});
     $self->{cfg}->{foulwords} = wordlist_regexp($self->{cfg}->{foulwords}, $self->{cfg}->{regexpaliases});
     $self->{cfg}->{ignorewords} = wordlist_regexp($self->{cfg}->{ignorewords}, $self->{cfg}->{regexpaliases});
     $self->{cfg}->{ignorewords} = wordlist_regexp($self->{cfg}->{ignorewords}, $self->{cfg}->{regexpaliases});
@@ -452,9 +463,6 @@ sub init_pisg
 
 
     unless ($self->{cfg}->{silent}) {
     unless ($self->{cfg}->{silent}) {
         print "Statistics for channel $self->{cfg}->{channel} \@ $self->{cfg}->{network} by $self->{cfg}->{maintainer}\n\n";
         print "Statistics for channel $self->{cfg}->{channel} \@ $self->{cfg}->{network} by $self->{cfg}->{maintainer}\n\n";
-        die sprintf "No such language: %s\n", $self->{cfg}->{lang}
-            unless $self->{tmps}->{$self->{cfg}->{lang}};
-        print "Using language template: $self->{cfg}->{lang}\n\n" if $self->{cfg}->{lang} ne 'EN';
     }
     }
 }
 }
 
 
@@ -510,7 +518,11 @@ _END
         # Create our HTML page if the logfile has any data.
         # Create our HTML page if the logfile has any data.
         if (defined $stats) {
         if (defined $stats) {
             if ($stats->{parsedlines} > 0) {
             if ($stats->{parsedlines} > 0) {
-                $generator->create_output();
+                foreach (@{ $self->{cfg}->{langlist} }) {
+                    s/-/_/g; # PT_BR was called PT-BR before
+                    die sprintf "No such language: %s\n", $_ unless $self->{tmps}->{$_};
+                    $generator->create_output($_);
+                }
             } else {
             } else {
                 print STDERR <<_END unless $self->{cfg}->{silent};
                 print STDERR <<_END unless $self->{cfg}->{silent};
 No parseable lines found in logfile ($stats->{totallines} total lines). Skipping.
 No parseable lines found in logfile ($stats->{totallines} total lines). Skipping.

+ 14 - 12
modules/Pisg/HTMLGenerator.pm

@@ -29,17 +29,6 @@ sub new
     require Pisg::Common;
     require Pisg::Common;
     Pisg::Common->import();
     Pisg::Common->import();
 
 
-    my $lang_charset = $self->{tmps}->{$self->{cfg}->{lang}}{lang_charset};
-    if($lang_charset and $lang_charset ne $self->{cfg}->{charset}) {
-        if($have_iconv) {
-            # convert from template charset to our
-            $self->{iconv} = Text::Iconv->new($lang_charset, $self->{cfg}->{charset});
-        } else {
-            print "Text::Iconv is not installed, skipping charset conversion of language templates\n"
-                unless ($self->{cfg}->{silent});
-        }
-    }
-
     bless($self, $type);
     bless($self, $type);
     return $self;
     return $self;
 }
 }
@@ -52,6 +41,18 @@ sub create_output
     # sub itself.
     # sub itself.
 
 
     my $self = shift;
     my $self = shift;
+    $self->{cfg}->{lang} = shift;
+
+    my $lang_charset = $self->{tmps}->{$self->{cfg}->{lang}}{lang_charset};
+    if($lang_charset and $lang_charset ne $self->{cfg}->{charset}) {
+        if($have_iconv) {
+            # convert from template charset to our
+            $self->{iconv} = Text::Iconv->new($lang_charset, $self->{cfg}->{charset});
+        } else {
+            print "Text::Iconv is not installed, skipping charset conversion of language templates\n"
+                unless ($self->{cfg}->{silent});
+        }
+    }
 
 
     $self->_topactive();
     $self->_topactive();
 
 
@@ -61,7 +62,8 @@ sub create_output
 
 
     my $fname = $self->{cfg}->{outputfile};
     my $fname = $self->{cfg}->{outputfile};
     $fname =~ s/\%t/$self->{cfg}->{outputtag}/g;
     $fname =~ s/\%t/$self->{cfg}->{outputtag}/g;
-    print "Now generating HTML in $fname...\n"
+    $fname =~ s/\%l/$self->{cfg}->{lang}/g;
+    print "Now generating HTML ($self->{cfg}->{lang}) in $fname...\n"
         unless ($self->{cfg}->{silent});
         unless ($self->{cfg}->{silent});
 
 
     open (OUTPUT, "> $fname") or
     open (OUTPUT, "> $fname") or