summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Install/Util.pm
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2009-11-18 08:06:45 +0100
committermkanat%bugzilla.org <>2009-11-18 08:06:45 +0100
commit3606f75dd1d18e5a3419c0b679ba3288fd203cf5 (patch)
tree9d8c75d71cceb60d11eb7df1db27aacb293d6dae /Bugzilla/Install/Util.pm
parenta44e152480c9c22ca9b3a89da774317c5590d21b (diff)
downloadbugzilla-3606f75dd1d18e5a3419c0b679ba3288fd203cf5.tar.gz
bugzilla-3606f75dd1d18e5a3419c0b679ba3288fd203cf5.tar.xz
Bug 421265: Let the user easily override the language used to display HTML pages
Patch by Jacques Supcik <jacques@supcik.org> r=mkanat, a=mkanat
Diffstat (limited to 'Bugzilla/Install/Util.pm')
-rw-r--r--Bugzilla/Install/Util.pm35
1 files changed, 32 insertions, 3 deletions
diff --git a/Bugzilla/Install/Util.pm b/Bugzilla/Install/Util.pm
index e53164d25..effb39ee8 100644
--- a/Bugzilla/Install/Util.pm
+++ b/Bugzilla/Install/Util.pm
@@ -127,15 +127,28 @@ sub install_string {
}
sub include_languages {
+ # If we are in CGI mode (not in checksetup.pl) and if the function has
+ # been called without any parameter, then we cache the result of this
+ # function in Bugzilla->request_cache. This is done to improve the
+ # performance of the template processing.
+ my $to_be_cached = 0;
+ if (exists $ENV{'SERVER_SOFTWARE'} and not @_) {
+ my $cache = Bugzilla->request_cache;
+ if (exists $cache->{include_languages}) {
+ return @{$cache->{include_languages}}
+ }
+ $to_be_cached = 1;
+ }
my ($params) = @_;
$params ||= {};
# 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. The caller tells us what languages they want, by setting
- # $ENV{HTTP_ACCEPT_LANGUAGE} or $params->{only_language}. The languages
- # we support are those specified in $params->{use_languages}. Otherwise
- # we support every language installed in the template/ directory.
+ # $ENV{HTTP_ACCEPT_LANGUAGE}, using the "LANG" cookie or setting
+ # $params->{only_language}. The languages we support are those
+ # specified in $params->{use_languages}. Otherwise we support every
+ # language installed in the template/ directory.
my @wanted;
if ($params->{only_language}) {
@@ -143,6 +156,15 @@ sub include_languages {
}
else {
@wanted = _sort_accept_language($ENV{'HTTP_ACCEPT_LANGUAGE'} || '');
+ # Don't use the cookie if we are in "checksetup.pl". The test
+ # with $ENV{'SERVER_SOFTWARE'} is the same as in
+ # Bugzilla:Util::i_am_cgi.
+ if (exists $ENV{'SERVER_SOFTWARE'}) {
+ my $cgi = Bugzilla->cgi;
+ if (defined (my $lang = $cgi->cookie('LANG'))) {
+ unshift @wanted, $lang;
+ }
+ }
}
my @supported;
@@ -175,6 +197,13 @@ sub include_languages {
push(@usedlanguages, 'en');
}
+ # Cache the result if we are in CGI mode and called without parameter
+ # (see the comment at the top of this function).
+ if ($to_be_cached) {
+ my $cache = Bugzilla->request_cache;
+ $cache->{include_languages} = \@usedlanguages;
+ }
+
return @usedlanguages;
}