[Debian-l10n-commits] r1208 - /ddtss/trunk/ddtss-cgi

grisu at users.alioth.debian.org grisu at users.alioth.debian.org
Thu Aug 14 23:53:22 UTC 2008


Author: grisu
Date: Thu Aug 14 23:53:21 2008
New Revision: 1208

URL: http://svn.debian.org/wsvn/?sc=1&rev=1208
Log:

   * add external review


Modified:
    ddtss/trunk/ddtss-cgi

Modified: ddtss/trunk/ddtss-cgi
URL: http://svn.debian.org/wsvn/ddtss/trunk/ddtss-cgi?rev=1208&op=diff
==============================================================================
--- ddtss/trunk/ddtss-cgi (original)
+++ ddtss/trunk/ddtss-cgi Thu Aug 14 23:53:21 2008
@@ -99,6 +99,10 @@
   if( $path eq "/" )
   {
     main_display();
+  }
+  elsif( $path =~ m,^/forexternalreview/([-\w+.]+)$, )
+  {
+    forexternalreview_display($1);
   }
   elsif( $path =~ m,^/translate/([-\w+.]+)$, )
   {
@@ -454,6 +458,105 @@
 }  
 
 # Display the screen that reviewers see
+sub forexternalreview_display
+{
+  my $package = shift;
+    
+  $q->charset("UTF-8");
+
+  my $db = DDTSS_Open_Write();
+
+  if( not DDTSS_Check_Valid_Language($db,$lang) )
+  {
+    DDTSS_Close($db);
+    display_langlist(); 
+    return;
+  }
+  
+  my $requirelogin = 0;
+
+  my($owner, $short, $long, $data, $reviewers, $timestamp );
+  
+  my $msg = '';
+
+  # Description adjusted, submit new version ... (mailing list etc)
+  if( defined $q->param("submit") )
+  {
+    $msg = submit_externalreview( $db, $package, $q->param("short"), $q->param("long"), $q->param("comment").$q->param("NameEMail") );
+    if( not defined $msg )
+    {
+      DDTSS_Close($db);
+      goto_main_display("Changes and comments for $package send to the team, thanks for your contribution");
+      exit;
+    }
+  }
+ 
+  eval {
+    $data = get_untrans( $lang, "", $package, "1" );
+  };
+  
+  # Any error/warning procuded, display it
+  if( $@ )
+  {
+    display_error($@);
+  }
+  if( not defined $data )
+  {
+    display_error("Couldn't fetch an untranslated description: $lang, $package");
+  }
+
+  if( not defined $data or $data !~ /Description:/ or $data !~ /Description-[a-z_A-Z]+:/)
+  {
+    display_error("Couldn't fetch package description");
+  }
+
+  if( $data !~ /^# Package[^:]*: ([\w.+-]+)/m )
+  { display_error( "Fetched description didn't contain package name" ) }
+  
+  eval {
+    my $str = Encode::decode_utf8($data, Encode::FB_CROAK);
+  };
+  if($@)
+  {
+    print STDERR "Encoding error ($@)\n";
+    print STDERR "Data: [$data]\n";
+    display_error("Encoding error retreiving data for package $package");
+  }
+  $data =~ s,^# patch http*,#  patch http,m; # don't show patch-box
+
+  ($short, $long) = ($data =~ /^Description-$lang: (.*)\n((?: .*\n)+)/m);
+
+  my($oldshort,$oldlong,$diffshort,$difflong);
+  
+  if( defined $oldshort and $short ne $oldshort )
+  {
+    $diffshort = make_colour_diff( $oldshort, $short );
+  }
+  
+  if( defined $oldlong and $long ne $oldlong )
+  {
+    $difflong = make_colour_diff( $oldlong, $long );
+  }
+  
+  my $trailer = $q->h5("Name and EMail-Address" ).
+		$q->ul(
+                  $q->input( { -type => 'text', -size => 52, -name => 'NameEMail' } ),
+                  $q->br(),
+		  ("With a email-Address the translator team can contact you, if they have questions.")
+		).
+                $q->br().
+                $q->submit(-name => "submit",  -label => "Send to team").
+                $q->br().
+                ("'Send to team' send the changes and the comments to the translator team.");
+
+  my $comment = "";
+  DDTSS_Close($db);
+
+  display_translate_screen( $data, "External Reviewing $package", $msg, $comment, $trailer,
+       $short, $long, $diffshort, $difflong );
+}
+
+# Display the screen that reviewers see
 sub forreview_display
 {
   my $package = shift;
@@ -713,6 +816,135 @@
 }
 
 
+sub submit_externalreview
+{
+  my( $db, $package, $short, $long, $comment ) = @_;
+  
+  $short =~ s/^\s+//;
+  $short =~ s/\s+$//;
+  $short =~ s/\s+/ /g;
+  $long =~ s/\s+$//;   # Trailing newlines
+  $long =~ s/\r\n?/\n/g;   # Fix line endings
+  $long =~ s/^[ \t]*$/./mg;  # Don't use \s because that matches \n
+  $long =~ s/[ \t]+$//mg;
+  $long =~ s/^/ /mg; # Insert leading space
+
+  eval {
+    my $shortx = Encode::decode_utf8($short, Encode::FB_CROAK);
+    my $longx = Encode::decode_utf8($long, Encode::FB_CROAK);
+    
+    if( length($shortx) > 80 or $longx =~ /^.{80}/m )
+    {
+      return "Translation contains line longer than 80 characters";
+    }
+  };
+  if( $@ )
+  {
+    print STDERR "Encoding failure: charset=[".$q->param("_charset_")."], browser=[$ENV{HTTP_USER_AGENT}], err=[$@]\n";
+    print STDERR "short=[$short]\n";
+    print STDERR "long=[$long]\n";
+    return "Entered data was not validly encoded. Please check your translation contains no invalid characters. If this error persists, contact me at <kleptog\@svana.org>";
+  }
+  
+  my $data;
+  my ($oldshort,$oldlong);
+  eval {
+    $data = get_untrans( $lang, "", $package, "1" );
+  };
+  
+  # Any error/warning procuded, display it
+  if( $@ )
+  {
+    return ($@);
+  }
+  if( not defined $data )
+  {
+    return("Couldn't fetch an untranslated description: $lang, $package");
+  }
+
+  if( not defined $data or $data !~ /Description:/ or $data !~ /Description-[a-z_A-Z]+:/)
+  {
+    return("Couldn't fetch package description");
+  }
+
+  if( $data !~ /^# Package[^:]*: ([\w.+-]+)/m )
+  { return( "Fetched description didn't contain package name" ) }
+  
+  eval {
+    my $str = Encode::decode_utf8($data, Encode::FB_CROAK);
+  };
+  if($@)
+  {
+    print STDERR "Encoding error ($@)\n";
+    print STDERR "Data: [$data]\n";
+    display_error("Encoding error retreiving data for package $package");
+  }
+  $data =~ s,^# patch http*,#  patch http,m; # don't show patch-box
+
+  ($oldshort, $oldlong) = ($data =~ /^Description-$lang: (.*)\n((?: .*\n)+)/m);
+ 
+  my $str1 = $oldshort . "\n" . $oldlong;
+  my $str2 = $short . "\n" . $long;
+  
+  my $words = 1;
+  if( $lang eq "ja" )
+  { $words = 0 }
+  
+  my $diff = DDTSS_CreateDiff( $str1, $str2, $words );
+  my $res = "";
+  for my $hunk (@$diff)
+  {
+    my($type,$str) = @$hunk;
+    $str = $q->escapeHTML($str);
+    
+    if( $type eq "" )
+    {
+      $res .= $str;
+    }
+    elsif( $type eq "-" )
+    {
+      $res .= "-(".$str.")";
+    }
+    elsif( $type eq "+" )
+    {
+      $res .= "+(".$str.")";
+    }
+  }
+  $diff=$res;
+
+  my $sender = setup_email_connection($db);
+  
+  DDTSS_Close($db);
+
+  my $email='grisu at debian.org, debian-i18n at lists.debian.org';
+  
+  $sender->MailMsg({to => $email, 
+	       	    from => 'debian-i18n at lists.debian.org',
+                    subject => "(test)External Description Review from '$package', lang '$lang'", 
+	       	    charset => 'UTF-8',
+                    msg => "Hi\n\n".
+		           "Somebody has made a review of the $lang-translation of package '$package'.\n\n".
+			   "The data in the database is:\n".
+			   $data.
+			   "\n\n".
+			   "The external reviewer has proposed the following change:\n\n".
+			   "Description-$lang: $short\n".
+			   $long.
+			   "\n\n".
+			   "The diff of the change:\n\n".
+			   $diff.
+			   "\n\n".
+			   "The reviewer made the following comment:\n\n".
+			   $comment.
+			   "\n\n".
+			   "To apply this change http://ddtp.debian.net/ddtss/index.cgi/$lang/fetch?package=$package&force=1 or \nsend an email to pdesc\@ddtp.debian.net\n\n".
+			   "Thanks"
+		   });
+ 
+  return undef;
+}
+
+
 sub submit_translation
 {
   my( $db, $package, $key, $short, $long ) = @_;




More information about the Debian-l10n-commits mailing list