From 8fc3249fa096b2f08ef751e44535eb8b5e462c1f Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Wed, 23 Sep 2009 14:56:44 +0200 Subject: [PATCH] (bug #3655) fix news language detection This patch improve the language detection for news in opac. If the user have no defined language in his browser. --- opac/opac-main.pl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/opac/opac-main.pl b/opac/opac-main.pl index 7535d67843..c4a44e98b8 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 accept_language); my $input = new CGI; my $dbh = C4::Context->dbh; @@ -47,7 +48,36 @@ $template->param( # display news # use cookie setting for language, bug default to syspref if it's not set +<<<<<<< HEAD:opac/opac-main.pl 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]; + } + } + if (not $news_lang) { + my @languages = split ",", C4::Context->preference("opaclanguages"); + $news_lang = @languages[0]; + } +} + +$news_lang = $news_lang ? $news_lang : 'en' ; + +>>>>>>> e25ac14... (bug #3655) fix news language detection:opac/opac-main.pl my $all_koha_news = &GetNewsToDisplay($news_lang); my $koha_news_count = scalar @$all_koha_news; -- 2.39.5