[Patches] [PATCH] Bug 7282 - invalid language selection

koha-patchbot at kohaaloha.com koha-patchbot at kohaaloha.com
Fri Dec 2 07:10:04 NZDT 2011


From: =?UTF-8?q?Fr=C3=A8re=20S=C3=A9bastien=20Marie?= <semarie-koha at latrappe.fr>
Date: Thu, 1 Dec 2011 19:02:11 +0100
Subject: [PATCH] Bug 7282 - invalid language selection

- ensure that without cookie, language selection is based on browser preferences
- refactor function to obtain langugage for stem in search (opac + intranet)
---
 C4/Templates.pm     |   54 ++++++++++++++++++++++++++++++--------------------
 catalogue/search.pl |    2 +-
 opac/opac-search.pl |    2 +-
 3 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/C4/Templates.pm b/C4/Templates.pm
index 73d94c2..0713664 100644
--- a/C4/Templates.pm
+++ b/C4/Templates.pm
@@ -273,21 +273,10 @@ sub themelanguage {
     ($query) or warn "no query in themelanguage";
 
     # Select a language based on cookie, syspref available languages & browser
-    my $is_intranet = $interface eq 'intranet';
-    my @languages = split(",", C4::Context->preference(
-        $is_intranet ? 'language' : 'opaclanguages'));
-    my $lang;
-    $lang = getlanguagecookie($query);
-    unless ($lang) {
-        my $http_accept_language = $ENV{ HTTP_ACCEPT_LANGUAGE };
-        $lang = accept_language( $http_accept_language, 
-            getTranslatedLanguages($interface,'prog') );
-    }
-    # Ignore a lang not selected in sysprefs
-    $lang = undef  unless first { $_ eq $lang } @languages;
-    # Fall back to English if necessary
-    $lang = 'en' unless $lang;
+    my $lang = getlanguage($query, $interface);
 
+    # Select theme
+    my $is_intranet = $interface eq 'intranet';
     my @themes = split(" ", C4::Context->preference(
         $is_intranet ? "template" : "opacthemes" ));
     push @themes, 'prog';
@@ -317,16 +306,37 @@ sub setlanguagecookie {
     );
 }
 
-sub getlanguagecookie {
-    my ($query) = @_;
+
+sub getlanguage {
+    my $query = shift;
+    my $interface = shift || 'opac';
+
+    # Select a language based on cookie, syspref available languages & browser
+    my $is_intranet = $interface eq 'intranet';
+    my @languages = split(",", C4::Context->preference(
+	$is_intranet ? 'language' : 'opaclanguages'));
+
     my $lang;
-    if ($query->cookie('KohaOpacLanguage')){
-        $lang = $query->cookie('KohaOpacLanguage') ;
-    }else{
-        $lang = $ENV{HTTP_ACCEPT_LANGUAGE};
-        
+
+    # cookie
+    if ( $query->cookie('KohaOpacLanguage') ) {
+	$lang = $query->cookie('KohaOpacLanguage');
+        $lang =~ s/[^a-zA-Z_-]*//; # sanitize cookie
+    }
+
+    # HTTP_ACCEPT_LANGUAGE
+    unless ($lang) {
+        my $http_accept_language = $ENV{ HTTP_ACCEPT_LANGUAGE };
+	$lang = accept_language( $http_accept_language,
+	    getTranslatedLanguages($interface,'prog') );
     }
-    $lang =~ s/[^a-zA-Z_-]*//; #sanitzie
+
+    # Ignore a lang not selected in sysprefs
+    $lang = undef  unless first { $_ eq $lang } @languages;
+
+    # Fall back to English if necessary
+    $lang = 'en' unless $lang;
+
     return $lang;
 }
 
diff --git a/catalogue/search.pl b/catalogue/search.pl
index 907efdb..bf9d45d 100755
--- a/catalogue/search.pl
+++ b/catalogue/search.pl
@@ -471,7 +471,7 @@ my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit
 my @results;
 
 ## I. BUILD THE QUERY
-my $lang = C4::Templates::getlanguagecookie($cgi);
+my $lang = C4::Templates::getlanguage($cgi);
 ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by,$scan,$lang);
 
 ## parse the query_cgi string and put it into a form suitable for <input>s
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index 42eb0ec..14908dc 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -388,7 +388,7 @@ my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_
 my @results;
 
 ## I. BUILD THE QUERY
-my $lang = C4::Templates::getlanguagecookie($cgi);
+my $lang = C4::Templates::getlanguage($cgi);
 ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by, 0, $lang);
 
 sub _input_cgi_parse ($) { 
-- 
1.7.2.5




More information about the Patches mailing list