[Koha-patches] [PATCH] 6755 Problems with switching languages

Marcel de Rooy M.de.Rooy at rijksmuseum.nl
Fri Sep 9 16:41:44 CEST 2011


This patch solves the situation that news is in another language than the Koha interface AND makes that themelanguage routine is always called the same way in order to prevent mixed display.

September 9: Adjusted with input of Frederic Demians.
---
 C4/Output.pm      |    2 +-
 C4/Templates.pm   |    3 ++-
 opac/opac-main.pl |   28 +---------------------------
 3 files changed, 4 insertions(+), 29 deletions(-)

diff --git a/C4/Output.pm b/C4/Output.pm
index 98f2d7a..2481fe7 100644
--- a/C4/Output.pm
+++ b/C4/Output.pm
@@ -96,7 +96,7 @@ sub gettemplate {
     my $opacstylesheet = C4::Context->preference('opacstylesheet');
     $tmplbase =~ s/\.tmpl$/.tt/;
     my ( $htdocs, $theme, $lang, $filename ) = _get_template_file( $tmplbase, $interface, $query );
-    my $template = C4::Templates->new( $interface, $filename, $tmplbase);
+    my $template = C4::Templates->new($interface, $filename, $tmplbase, $query);
     my $themelang=( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' )
           . "/$theme/$lang";
     $template->param(
diff --git a/C4/Templates.pm b/C4/Templates.pm
index 4368492..e0a01f8 100644
--- a/C4/Templates.pm
+++ b/C4/Templates.pm
@@ -41,6 +41,7 @@ sub new {
     my $interface = shift;
     my $filename  = shift;
     my $tmplbase  = shift;
+    my $query     = @_? shift: undef;
     my $htdocs;
     if ( $interface ne "intranet" ) {
         $htdocs = C4::Context->config('opachtdocs');
@@ -49,7 +50,7 @@ sub new {
         $htdocs = C4::Context->config('intrahtdocs');
     }

-    my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface );
+    my ($theme, $lang)= C4::Output::themelanguage( $htdocs, $tmplbase, $interface, $query);
     my $template = Template->new(
         {
             EVAL_PERL    => 1,
diff --git a/opac/opac-main.pl b/opac/opac-main.pl
index 177d812..cd76bc7 100755
--- a/opac/opac-main.pl
+++ b/opac/opac-main.pl
@@ -54,33 +54,7 @@ $template->param(

 # display news
 # use cookie setting for language, bug default to syspref if it's not set
-(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{
-    if ($ENV{HTTP_ACCEPT_LANGUAGE}) {
-        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' ;
+my ($theme, $news_lang) = C4::Output::themelanguage(C4::Context->config('opachtdocs'),'opac-main.tt','opac',$input);

 my $all_koha_news   = &GetNewsToDisplay($news_lang);
 my $koha_news_count = scalar @$all_koha_news;
--
1.6.0.6


More information about the Koha-patches mailing list