From 22f1b7eb4d32020ca57739266516705e7ece6457 Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Thu, 17 Jan 2013 16:19:47 -0500 Subject: Bug 830467 - Don't call _wanted_languages() when only one is available --- Bugzilla.pm | 10 +++++++++- Bugzilla/Install/Util.pm | 6 ++++-- Bugzilla/Template.pm | 11 +++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Bugzilla.pm b/Bugzilla.pm index 28098cb65..5773eee63 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -47,7 +47,7 @@ use Bugzilla::DB; use Bugzilla::Hook; use Bugzilla::Install::Localconfig qw(read_localconfig); use Bugzilla::Install::Requirements qw(OPTIONAL_MODULES); -use Bugzilla::Install::Util qw(init_console); +use Bugzilla::Install::Util qw(init_console include_languages); use Bugzilla::Template; use Bugzilla::User; use Bugzilla::Error; @@ -433,6 +433,10 @@ sub languages { return Bugzilla::Install::Util::supported_languages(); } +sub current_language { + return $_[0]->request_cache->{current_language} ||= (include_languages())[0]; +} + sub error_mode { my ($class, $newval) = @_; if (defined $newval) { @@ -921,6 +925,10 @@ The main database handle. See L. Currently installed languages. Returns a reference to a list of RFC 1766 language tags of installed languages. +=item C + +The currently active language. + =item C Switch from using the main database to using the shadow database. diff --git a/Bugzilla/Install/Util.pm b/Bugzilla/Install/Util.pm index bd8942507..5f6c8bceb 100644 --- a/Bugzilla/Install/Util.pm +++ b/Bugzilla/Install/Util.pm @@ -382,7 +382,10 @@ sub include_languages { # Basically, the way this works is that we have a list of languages # that we *want*, and a list of languages that Bugzilla actually - # supports. + # supports. If there is only one language installed, we take it. + my $supported = supported_languages(); + return @$supported if @$supported == 1; + my $wanted; if ($params->{language}) { # We can pass several languages at once as an arrayref @@ -393,7 +396,6 @@ sub include_languages { else { $wanted = _wanted_languages(); } - my $supported = supported_languages(); my $actual = _wanted_to_actual_languages($wanted, $supported); return @$actual; } diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 5ef7ed1c6..b19943b03 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -871,14 +871,9 @@ sub create { # Currently logged in user, if any # If an sudo session is in progress, this is the user we're faking 'user' => sub { return Bugzilla->user; }, - + # Currenly active language - # XXX Eventually this should probably be replaced with something - # like Bugzilla->language. - 'current_language' => sub { - my ($language) = include_languages(); - return $language; - }, + 'current_language' => sub { return Bugzilla->current_language; }, # If an sudo session is in progress, this is the user who # started the session. @@ -889,7 +884,7 @@ sub create { # Allow templates to access docs url with users' preferred language 'docs_urlbase' => sub { - my ($language) = include_languages(); + my $language = Bugzilla->current_language; my $docs_urlbase = Bugzilla->params->{'docs_urlbase'}; $docs_urlbase =~ s/\%lang\%/$language/; return $docs_urlbase; -- cgit v1.2.3-24-g4f1b