Bugzilla->template_inner("")).
r=LpSolit, a=LpSolit
sub template {
my $class = shift;
- $class->request_cache->{language} = "";
$class->request_cache->{template} ||= Bugzilla::Template->create();
return $class->request_cache->{template};
}
sub template_inner {
my ($class, $lang) = @_;
- $lang = defined($lang) ? $lang : ($class->request_cache->{language} || "");
- $class->request_cache->{language} = $lang;
+ my $cache = $class->request_cache;
+ my $current_lang = $cache->{template_current_lang}->[0];
+ $lang ||= $current_lang || '';
$class->request_cache->{"template_inner_$lang"}
- ||= Bugzilla::Template->create();
+ ||= Bugzilla::Template->create(language => $lang);
return $class->request_cache->{"template_inner_$lang"};
}
my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
$template->process("email/newchangedmail.txt.tmpl", $vars, \$msg)
|| ThrowTemplateError($template->error());
- Bugzilla->template_inner("");
MessageToMTA($msg);
$template->process("request/email.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error());
- Bugzilla->template_inner("");
MessageToMTA($message);
}
}
# settings of the user and of the available languages
# If no Accept-Language is present it uses the defined default
# Templates may also be found in the extensions/ tree
-sub getTemplateIncludePath {
+sub _include_path {
+ my $lang = shift || '';
my $cache = Bugzilla->request_cache;
- my $lang = $cache->{'language'} || '';
$cache->{"template_include_path_$lang"} ||=
template_include_path({ language => $lang });
return $cache->{"template_include_path_$lang"};
###############################################################################
+sub process {
+ my $self = shift;
+ # All of this current_langs stuff allows template_inner to correctly
+ # determine what-language Template object it should instantiate.
+ my $current_langs = Bugzilla->request_cache->{template_current_lang} ||= [];
+ unshift(@$current_langs, $self->context->{bz_language});
+ my $retval = $self->SUPER::process(@_);
+ shift @$current_langs;
+ return $retval;
+}
+
# Construct the Template object
# Note that all of the failure cases here can't use templateable errors,
my $config = {
# Colon-separated list of directories containing templates.
- INCLUDE_PATH => $opts{'include_path'} || getTemplateIncludePath(),
+ INCLUDE_PATH => $opts{'include_path'}
+ || _include_path($opts{'language'}),
# Remove white-space before template directives (PRE_CHOMP) and at the
# beginning and end of templates and template blocks (TRIM) for better
Bugzilla::Hook::process('template_before_create', { config => $config });
my $template = $class->new($config)
|| die("Template creation failed: " . $class->error());
+
+ # Pass on our current language to any template hooks or inner templates
+ # called by this Template object.
+ $template->context->{bz_language} = $opts{language} || '';
+
return $template;
}
# Get the hooks out of the cache if they exist. Otherwise, read them
# from the disk.
my $cache = Bugzilla->request_cache->{template_plugin_hook_cache} ||= {};
- my $lang = Bugzilla->request_cache->{language} || '';
+ my $lang = $context->{bz_language} || '';
$cache->{"${lang}__$extension_template"}
||= $self->_get_hooks($extension_template);
sub _get_hooks {
my ($self, $extension_template) = @_;
- my $template_sets = _template_hook_include_path();
+ my $template_sets = $self->_template_hook_include_path();
my @hooks;
foreach my $dir_set (@$template_sets) {
foreach my $template_dir (@$dir_set) {
}
sub _template_hook_include_path {
+ my $self = shift;
my $cache = Bugzilla->request_cache;
- my $language = $cache->{language} || '';
+ my $language = $self->_context->{bz_language} || '';
my $cache_key = "template_plugin_hook_include_path_$language";
$cache->{$cache_key} ||= template_include_path({
language => $language,
$template->process("account/email/change-new.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error());
- Bugzilla->template_inner("");
MessageToMTA($message);
}
$vars, \$message)
|| ThrowTemplateError($template->error());
- Bugzilla->template_inner("");
MessageToMTA($message);
}
$template->process("account/cancel-token.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error());
- Bugzilla->template_inner("");
MessageToMTA($message);
# Delete the token from the database.
$template->process("voting/votes-removed.txt.tmpl", $vars, \$msg);
push(@messages, $msg);
}
- Bugzilla->template_inner("");
my $votes = $dbh->selectrow_array("SELECT SUM(vote_count) " .
"FROM votes WHERE bug_id = ?",
my $message;
my $mail_template = Bugzilla->template_inner($target_user->settings->{'lang'}->{'value'});
$mail_template->process('email/sudo.txt.tmpl', { reason => $reason }, \$message);
- Bugzilla->template_inner("");
MessageToMTA($message);
$vars->{'message'} = 'sudo_started';
$template->process("whine/multipart-mime.txt.tmpl", $args, \$msg)
or die($template->error());
- Bugzilla->template_inner("");
MessageToMTA($msg);
delete $args->{'boundary'};
$template->process("email/whine.txt.tmpl", $vars, \$msg)
or die($template->error());
- Bugzilla->template_inner("");
MessageToMTA($msg);
print "$email " . join(" ", @{$bugs{$email}}) . "\n";