]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 457657 รข\80\93 Make e-mail comment header localizable.
authorwurblzap%gmail.com <>
Tue, 2 Jun 2009 22:04:12 +0000 (22:04 +0000)
committerwurblzap%gmail.com <>
Tue, 2 Jun 2009 22:04:12 +0000 (22:04 +0000)
Patch by Marc Schumann <wurblzap@gmail.com>,
r/a=LpSolit

Bugzilla/Bug.pm
Bugzilla/BugMail.pm
Bugzilla/User.pm
template/en/default/bug/format_comment.txt.tmpl [new file with mode: 0755]
template/en/default/email/newchangedmail.txt.tmpl
template/en/default/global/messages.html.tmpl

index 79cf1dd5e2ff4c619004b9cd1c7e4cb7b68d5ac9..f1fc9c42483ba022240e4968fa7683a7b3d15675 100644 (file)
@@ -3060,29 +3060,15 @@ sub GetComments {
     return \@comments;
 }
 
-# Format language specific comments. This routine must not update
-# $comment{'body'} itself, see BugMail::prepare_comments().
+# Format language specific comments.
 sub format_comment {
     my $comment = shift;
+    my $template = Bugzilla->template_inner;
+    my $vars = {comment => $comment};
     my $body;
 
-    if ($comment->{'type'} == CMT_DUPE_OF) {
-        $body = $comment->{'body'} . "\n\n" .
-                get_text('bug_duplicate_of', { dupe_of => $comment->{'extra_data'} });
-    }
-    elsif ($comment->{'type'} == CMT_HAS_DUPE) {
-        $body = get_text('bug_has_duplicate', { dupe => $comment->{'extra_data'} });
-    }
-    elsif ($comment->{'type'} == CMT_POPULAR_VOTES) {
-        $body = get_text('bug_confirmed_by_votes');
-    }
-    elsif ($comment->{'type'} == CMT_MOVED_TO) {
-        $body = $comment->{'body'} . "\n\n" .
-                get_text('bug_moved_to', { login => $comment->{'extra_data'} });
-    }
-    else {
-        $body = $comment->{'body'};
-    }
+    $template->process("bug/format_comment.txt.tmpl", $vars, \$body)
+        || ThrowTemplateError($template->error());
     return $body;
 }
 
index 9f7b2e7536a3726c087a6ae59d4073b920c2fdcc..9a1b2a8a258adcf37f6c68eaa44de47a58e90d7c 100644 (file)
@@ -357,7 +357,7 @@ sub Send {
         }
     }
 
-    my ($raw_comments, $anyprivate, $count) = get_comments_by_bug($id, $start, $end);
+    my ($comments, $anyprivate) = get_comments_by_bug($id, $start, $end);
 
     ###########################################################################
     # Start of email filtering code
@@ -450,9 +450,6 @@ sub Send {
     my @sent;
     my @excluded;
 
-    # Some comments are language specific. We cache them here.
-    my %comments;
-
     foreach my $user_id (keys %recipients) {
         my %rels_which_want;
         my $sent_mail = 0;
@@ -461,24 +458,14 @@ sub Send {
         # Deleted users must be excluded.
         next unless $user;
 
-        # What's the language chosen by this user for email?
-        my $lang = $user->settings->{'lang'}->{'value'};
-
         if ($user->can_see_bug($id)) {
-            # It's time to format language specific comments.
-            unless (exists $comments{$lang}) {
-                Bugzilla->template_inner($lang);
-                $comments{$lang} = prepare_comments($raw_comments, $count);
-                Bugzilla->template_inner("");
-            }
-
             # Go through each role the user has and see if they want mail in
             # that role.
             foreach my $relationship (keys %{$recipients{$user_id}}) {
                 if ($user->wants_bug_mail($id,
                                           $relationship, 
                                           $diffs, 
-                                          $comments{$lang},
+                                          $comments,
                                           $deptext,
                                           $changer,
                                           !$start))
@@ -524,7 +511,7 @@ sub Send {
                                       \%defmailhead, 
                                       \%fielddescription, 
                                       \@diffparts,
-                                      $comments{$lang},
+                                      $comments,
                                       $anyprivate, 
                                       ! $start, 
                                       $id,
@@ -607,7 +594,7 @@ sub sendMail {
         $newcomments =~ s/(Created an attachment \(id=([0-9]+)\))/$1\n --> \(${showattachurlbase}$2\)/g;
     }
 
-    my $diffs = $difftext . "\n\n" . $newcomments;
+    my $diffs = $difftext;
     if ($isnew) {
         my $head = "";
         foreach my $f (@headerlist) {
@@ -663,6 +650,7 @@ sub sendMail {
         reporter => $values{'reporter'},
         reportername => Bugzilla::User->new({name => $values{'reporter'}})->name,
         diffs => $diffs,
+        new_comments => $newcomments,
         threadingmarker => build_thread_marker($id, $user->id, $isnew),
     };
 
@@ -698,31 +686,15 @@ sub get_comments_by_bug {
     my $raw = 1; # Do not format comments which are not of type CMT_NORMAL.
     my $comments = Bugzilla::Bug::GetComments($id, "oldest_to_newest", $start, $end, $raw);
 
+    foreach my $comment (@$comments) {
+        $comment->{count} = $count++;
+    }
+
     if (Bugzilla->params->{'insidergroup'}) {
         $anyprivate = 1 if scalar(grep {$_->{'isprivate'} > 0} @$comments);
     }
 
-    return ($comments, $anyprivate, $count);
-}
-
-# Prepare comments for the given language.
-sub prepare_comments {
-    my ($raw_comments, $count) = @_;
-
-    my $result = "";
-    foreach my $comment (@$raw_comments) {
-        if ($count) {
-            $result .= "\n\n--- Comment #$count from " . $comment->{'author'}->identity .
-                       "  " . format_time($comment->{'time'}) . " ---\n";
-        }
-        # Format language specific comments. We don't update $comment->{'body'}
-        # directly, otherwise it would grow everytime you call format_comment()
-        # with a different language as some text may be appended to the existing one.
-        my $body = Bugzilla::Bug::format_comment($comment);
-        $result .= ($comment->{'already_wrapped'} ? $body : wrap_comment($body));
-        $count++;
-    }
-    return $result;
+    return ($comments, $anyprivate);
 }
 
 1;
index 20f1707646f68e86902cf05c80c8e6f3cb502f5b..7f1b3892530d63e68dd9c0f8c0bfb701580194d7 100644 (file)
@@ -1377,8 +1377,9 @@ our %names_to_events = (
 # Note: the "+" signs before the constants suppress bareword quoting.
 sub wants_bug_mail {
     my $self = shift;
-    my ($bug_id, $relationship, $fieldDiffs, $commentField, $dependencyText,
+    my ($bug_id, $relationship, $fieldDiffs, $comments, $dependencyText,
         $changer, $bug_is_new) = @_;
+    my $comments_concatenated = join("\n", map { $_->{body} } (@$comments));
 
     # Make a list of the events which have happened during this bug change,
     # from the point of view of this user.    
@@ -1427,10 +1428,10 @@ sub wants_bug_mail {
         }
     }
 
-    if ($commentField =~ /Created an attachment \(/) {
+    if ($comments_concatenated =~ /Created an attachment \(/) {
         $events{+EVT_ATTACHMENT} = 1;
     }
-    elsif ($commentField ne '') {
+    elsif (defined($$comments[0])) {
         $events{+EVT_COMMENT} = 1;
     }
     
diff --git a/template/en/default/bug/format_comment.txt.tmpl b/template/en/default/bug/format_comment.txt.tmpl
new file mode 100755 (executable)
index 0000000..6da39e6
--- /dev/null
@@ -0,0 +1,61 @@
+[%# The contents of this file are subject to the Mozilla Public
+  # License Version 1.1 (the "License"); you may not use this file
+  # except in compliance with the License. You may obtain a copy of
+  # the License at http://www.mozilla.org/MPL/
+  #
+  # Software distributed under the License is distributed on an "AS
+  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+  # implied. See the License for the specific language governing
+  # rights and limitations under the License.
+  #
+  # The Original Code is the Bugzilla Bug Tracking System.
+  #
+  # The Initial Developer of the Original Code is Marc Schumann.
+  # Portions created by Marc Schumann are Copyright (c) 2008 Marc Schumann.
+  # All rights reserved.
+  #
+  # Contributor(s): Marc Schumann <wurblzap@gmail.com>
+  #%]
+
+[%# INTERFACE:
+  #   comment: A hash containing comment information.
+  #              count:           The comment number (on the bug it belongs to)
+  #              author:          The Bugzilla::User object of the comment's
+  #                               author
+  #              time:            The time at which the comment has been
+  #                               committed
+  #              body:            The comment text
+  #              type:            One of the CMT_* constants (not given if none
+  #                               applies)
+  #              extra_data:      Extra data (type specific)
+  #              already_wrapped: Determines whether the comment is pre-wrapped
+  #%]
+
+[% PROCESS 'global/field-descs.none.tmpl' %]
+
+[% IF comment.already_wrapped %]
+  [% wrapped_comment = comment.body %]
+[% ELSE %]
+  [% wrapped_comment = comment.body FILTER wrap_comment %]
+[% END %]
+
+[%- IF comment.type == constants.CMT_DUPE_OF -%]
+[% wrapped_comment %]
+
+*** This [% terms.bug %] has been marked as a duplicate of [% terms.bug %] [%+ comment.extra_data %] ***
+[% ELSIF comment.type == constants.CMT_HAS_DUPE %]
+*** [% terms.Bug %] [%+ comment.extra_data %] has been marked as a duplicate of this [% terms.bug %]. ***
+[% ELSIF comment.type == constants.CMT_POPULAR_VOTES %]
+*** This [% terms.bug %] has been confirmed by popular vote. ***
+[% ELSIF comment.type == constants.CMT_MOVED_TO %]
+[% wrapped_comment %]
+
+[%+ terms.Bug %] moved to [% Param("move-to-url") %].
+If the move succeeded, [% comment.extra_data %] will receive a mail containing
+the number of the new [% terms.bug %] in the other database.
+If all went well, please mark this [% terms.bug %]
+[%+ get_status('VERIFIED') %], and paste in a link to the new [% terms.bug %].
+Otherwise, reopen this [% terms.bug %].
+[%- ELSE -%]
+[%- wrapped_comment %]
+[% END %]
index 613e174f002888e80c7e5bde811035bfab68fd87..494c12060f0ee4f58870513ddb8deb2ce3069d0a 100644 (file)
@@ -43,8 +43,13 @@ X-Bugzilla-Changed-Fields: [% changedfields %]
 [%+ urlbase %]show_bug.cgi?id=[% bugid %]
 
 [%+ diffs %]
+[% FOREACH comment = new_comments %]
 
--- 
+--- Comment #[% comment.count %] from [% comment.author.identity %] [%+ comment.time FILTER time %] ---
+[%+ PROCESS bug/format_comment.txt.tmpl comment = comment %]
+[% END %]
+
+-- [%# Protect the trailing space of the signature marker %]
 Configure [% terms.bug %]mail: [% urlbase %]userprefs.cgi?tab=email
 ------- You are receiving this mail because: -------
 [% FOREACH relationship = reasons %]
index c8e4dd225a78a6120568caca77cede70c59ffc10..6be3a6477063acebd094f84ee9b766d8bab25fa7 100644 (file)
     Please add your attachment by clicking the "Add an Attachment" link
     below.
 
-  [% ELSIF message_tag == "bug_confirmed_by_votes" %]
-    *** This [% terms.bug %] has been confirmed by popular vote. ***
-
-  [% ELSIF message_tag == "bug_duplicate_of" %]
-    *** This [% terms.bug %] has been marked as a duplicate of [% terms.bug %] [%+ dupe_of FILTER html %] ***
-
-  [% ELSIF message_tag == "bug_has_duplicate" %]
-    *** [% terms.Bug %] [%+ dupe FILTER html %] has been marked as a duplicate of this [% terms.bug %]. ***
-
   [% ELSIF message_tag == "bug_group_description" %]
     Access to [% terms.bugs %] in the [% product.name FILTER html %] product
 
-  [% ELSIF message_tag == "bug_moved_to" %]
-    <p>[% terms.Bug %] moved to [% Param("move-to-url") FILTER html %].</p>
-    <p>If the move succeeded, [% login FILTER html %] will receive a mail
-    containing the number of the new [% terms.bug %] in the other database.
-    If all went well, please mark this [% terms.bug %] verified, and paste
-    in a link to the new [% terms.bug %]. Otherwise, reopen this [% terms.bug %].
-
   [% ELSIF message_tag == "buglist_adding_field" %]
     [% title = "Adding field to search page..." %]
     [% link  = "Click here if the page does not redisplay automatically." %]