[Koha-patches] [PATCH] Fix the language detection, to use the browser language if opac is translated, so show the news for the browser's language.

Nahuel Angelinetti nahuel.angelinetti at biblibre.com
Fri Oct 10 11:34:56 CEST 2008


---
 opac/opac-main.pl |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/opac/opac-main.pl b/opac/opac-main.pl
index 1bce420..a29eddf 100755
--- a/opac/opac-main.pl
+++ b/opac/opac-main.pl
@@ -26,6 +26,7 @@ use C4::Branch;          # GetBranches
 use C4::Members;         # GetMember
 use C4::NewsChannels;    # get_opac_news
 use C4::Acquisition;     # GetRecentAcqui
+use C4::Languages qw(getTranslatedLanguages);
 
 my $input = new CGI;
 my $dbh   = C4::Context->dbh;
@@ -47,7 +48,28 @@ $template->param(
 
 # display news
 # use cookie setting for language, bug default to syspref if it's not set
-my $news_lang = $input->cookie('KohaOpacLanguage') || 'en';
+(my $theme) = themelanguage(C4::Context->config('opachtdocs'),'opac-main.tmpl','opac',$input);
+
+my $translations = getTranslatedLanguages('opac',$theme);
+my @languages = ();
+foreach my $trans (@$translations)
+{
+    push(@languages, $trans->{rfc4646_subtag});
+}
+
+my $news_lang;
+if($input->cookie('KohaOpacLanguage')){
+    $news_lang = $input->cookie('KohaOpacLanguage');
+}else{
+    while( !$news_lang && ( $ENV{HTTP_ACCEPT_LANGUAGE} =~ m/([a-zA-Z]{2,}-?[a-zA-Z]*)(;|,)?/g ) ){
+        if( my @lang = grep { /^$1$/i } @languages ) {
+            $news_lang = $lang[0];
+        }
+    }
+}
+
+$news_lang = $news_lang ? $news_lang : 'en' ;
+
 my $all_koha_news   = &GetNewsToDisplay($news_lang);
 my $koha_news_count = scalar @$all_koha_news;
 
-- 
1.5.4.3




More information about the Koha-patches mailing list