[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.
henridamien.laurent at biblibre.com
henridamien.laurent at biblibre.com
Fri Mar 6 11:37:46 CET 2009
From: Nahuel Angelinetti <nahuel.angelinetti at biblibre.com>
Signed-off-by: Henri-Damien LAURENT <henridamien.laurent at biblibre.com>
---
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 1062109..704dc75 100755
--- a/opac/opac-main.pl
+++ b/opac/opac-main.pl
@@ -25,6 +25,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;
@@ -46,7 +47,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.6.3
More information about the Koha-patches
mailing list