From 62d16aa6b750aaade2267596c19292659333f8c8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 25 Jul 2016 16:37:03 +0100 Subject: [PATCH] Bug 16776: Do not forget external language choice in language switcher If language is set by external link language switcher does not work To reproduce: - Have a multilingual koha installation, let's say en, de-CH, fr-FR and it-IT - Create external links e.g. from your multilingual library website to each language variant of OPAC: ...cgi-bin/koha/opac-main.pl?language=en ...cgi-bin/koha/opac-main.pl?language=de-CH ...cgi-bin/koha/opac-main.pl?language=fr-FR ...cgi-bin/koha/opac-main.pl?language=it-IT Each link opens fine displaying the language as appropriate. Now try to switch language on the page you just opened via the external link. It won't work, it will always stay on the language defined by the external link. To test: - Apply patch - Repeat steps above - Verify that the language switcher works - Verify in browser address field that after switching language, the param 'language= 'has vanished from url string - Try links with multiple params and with params containing 'language', e.g. ...cgi-bin/koha/opac-search.pl?language=fr-FR&q=language&mylanguage=test - Verify that only the parameter 'language=' vanishes Tested counter patch, works as well. Signed-off-by: Marc Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall --- changelanguage.pl | 4 +++- opac/opac-changelanguage.pl | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/changelanguage.pl b/changelanguage.pl index 9a72f8dcba..360484c5fa 100755 --- a/changelanguage.pl +++ b/changelanguage.pl @@ -25,5 +25,7 @@ my $query = new CGI; my $language = $query->param('language'); my $url = $query->referer(); -#warn "Language : $query // $language // $url"; +$url =~ s|(.)language=[\w-]*&?|$1|; +$url =~ s|(&\|\?)$||; # Remove extraneous ? or & + C4::Templates::setlanguagecookie( $query, $language, $url ); diff --git a/opac/opac-changelanguage.pl b/opac/opac-changelanguage.pl index 2773704e02..9c68ab46f6 100755 --- a/opac/opac-changelanguage.pl +++ b/opac/opac-changelanguage.pl @@ -25,4 +25,11 @@ my $language = $query->param('language'); my $url = $query->referer() || '/'; # warn "Language : $query // $language // $url"; + +# If language was set by an external URL the parameter +# 'language=' should be removed from url string, otherwise +# the language picker will not work +$url =~ s|(.)language=[\w-]*&?|$1|; +$url =~ s|(&\|\?)$||; # Remove extraneous ? or & + C4::Templates::setlanguagecookie( $query, $language, $url ); -- 2.39.5