(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.
This commit is contained in:
Nahuel ANGELINETTI 2009-09-23 14:56:44 +02:00 committed by Henri-Damien LAURENT
parent 2bf19bc97a
commit 8fc3249fa0

View file

@ -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;