summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Template.pm
diff options
context:
space:
mode:
authorFrédéric Buclin <LpSolit@gmail.com>2010-08-06 12:41:54 +0200
committerFrédéric Buclin <LpSolit@gmail.com>2010-08-06 12:41:54 +0200
commitc1d01f36129ccfa0f76f4681058b10a348a6e9a2 (patch)
tree866d5a85bae4b22618eafa666c3c24dd050eafbd /Bugzilla/Template.pm
parentc3347fb736a9f08c8285dc31881ed6301412e9ac (diff)
downloadbugzilla-c1d01f36129ccfa0f76f4681058b10a348a6e9a2.tar.gz
bugzilla-c1d01f36129ccfa0f76f4681058b10a348a6e9a2.tar.xz
Bug 466968: Remove hardcoded strings from BugMail.pm, and refactor it so that bugmails are 100% localizable
r/a=mkanat
Diffstat (limited to 'Bugzilla/Template.pm')
-rw-r--r--Bugzilla/Template.pm43
1 files changed, 43 insertions, 0 deletions
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index 923336d45..c964dd022 100644
--- a/Bugzilla/Template.pm
+++ b/Bugzilla/Template.pm
@@ -61,6 +61,11 @@ use Scalar::Util qw(blessed);
use base qw(Template);
+use constant FORMAT_TRIPLE => '%19s|%-28s|%-28s';
+use constant FORMAT_3_SIZE => [19,28,28];
+use constant FORMAT_DOUBLE => '%19s %-55s';
+use constant FORMAT_2_SIZE => [19,55];
+
# Convert the constants in the Bugzilla::Constants module into a hash we can
# pass to the template object for reflection into its "constants" namespace
# (which is like its "variables" namespace, but for constants). To do so, we
@@ -352,6 +357,36 @@ sub get_bug_link {
return qq{$pre<a href="$linkval" title="$title">$link_text</a>$post};
}
+# We use this instead of format because format doesn't deal well with
+# multi-byte languages.
+sub multiline_sprintf {
+ my ($format, $args, $sizes) = @_;
+ my @parts;
+ my @my_sizes = @$sizes; # Copy this so we don't modify the input array.
+ foreach my $string (@$args) {
+ my $size = shift @my_sizes;
+ my @pieces = split("\n", wrap_hard($string, $size));
+ push(@parts, \@pieces);
+ }
+
+ my $formatted;
+ while (1) {
+ # Get the first item of each part.
+ my @line = map { shift @$_ } @parts;
+ # If they're all undef, we're done.
+ last if !grep { defined $_ } @line;
+ # Make any single undef item into ''
+ @line = map { defined $_ ? $_ : '' } @line;
+ # And append a formatted line
+ $formatted .= sprintf($format, @line);
+ # Remove trailing spaces, or they become lots of =20's in
+ # quoted-printable emails.
+ $formatted =~ s/\s+$//;
+ $formatted .= "\n";
+ }
+ return $formatted;
+}
+
#####################
# Header Generation #
#####################
@@ -833,6 +868,14 @@ sub create {
# Function to create date strings
'time2str' => \&Date::Format::time2str,
+ # Fixed size column formatting for bugmail.
+ 'format_columns' => sub {
+ my $cols = shift;
+ my $format = ($cols == 3) ? FORMAT_TRIPLE : FORMAT_DOUBLE;
+ my $col_size = ($cols == 3) ? FORMAT_3_SIZE : FORMAT_2_SIZE;
+ return multiline_sprintf($format, \@_, $col_size);
+ },
+
# Generic linear search function
'lsearch' => sub {
my ($array, $item) = @_;