From bfbc6cc941632269582891d63c58cea8b4fe668f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 9 Apr 2018 11:30:01 -0300 Subject: [PATCH] Bug 19817: Use the language from the interface if valid Use the UI language for the manual, if exists. Use the pref as a fallback. With the call to get_template_and_user the value of preferred_language switched from 'es' (spanish) to 'en' from one click to another (??) Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- Koha/Manual.pm | 16 +++++++++++++--- help.pl | 15 ++++++++++++++- .../admin/preferences/enhanced_content.pref | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Koha/Manual.pm b/Koha/Manual.pm index fe0c3a2998..cab6156f95 100644 --- a/Koha/Manual.pm +++ b/Koha/Manual.pm @@ -17,8 +17,18 @@ sub _get_help_version { } sub _get_base_url { + my ( $preferred_language ) = @_; + + my @available_languages = qw( en ar cs es fr it pt_BZ tz zh_TW ); + + my ( $language ) = grep { + my $preferred_short = substr $preferred_language, 0, 2; + my $avail_short = substr $_, 0, 2; + $preferred_short eq $avail_short ? $_ : () + } @available_languages; + + my $KohaManualLanguage = $language || C4::Context->preference('KohaManualLanguage') || 'en'; my $KohaManualBaseURL = C4::Context->preference('KohaManualBaseURL') || 'http://koha-community.org/manual'; - my $KohaManualLanguage = C4::Context->preference('KohaManualLanguage') || 'en'; if ( $KohaManualBaseURL =~ m|^/| ) { $KohaManualBaseURL = C4::Context->preference('staffClientBaseURL') . $KohaManualBaseURL; } @@ -221,7 +231,7 @@ our $mapping = { }; sub get_url { - my $url = shift; + my ( $url, $preferred_language ) = @_; my $file; if ($url =~ /koha\/(.*)\.pl/) { $file = $1; @@ -230,7 +240,7 @@ sub get_url { } $file =~ s/[^a-zA-Z0-9_\-\/]*//g; - my $base_url = _get_base_url; + my $base_url = _get_base_url( $preferred_language ); return $base_url . ( exists $mapping->{$file} ? $mapping->{$file} : $mapping->{mainpage} ); } diff --git a/help.pl b/help.pl index df946491e5..b39c5773f1 100755 --- a/help.pl +++ b/help.pl @@ -20,15 +20,28 @@ use Modern::Perl; use CGI qw ( -utf8 ); +use C4::Auth; use C4::Context; use Koha::Manual; my $query = new CGI; +# We need to call get_template_and_user to let it does the job correctly +# for the language +my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( + { + template_name => "intranet-main.tt", # Just a valid template path + query => $query, + type => "intranet", + authnotrequired => 1, + } +); + # find the script that called the online help using the CGI referer() our $refer = $query->param('url'); $refer = $query->referer() if !$refer || $refer eq 'undefined'; -my $manual_url = Koha::Manual::get_url($refer); +my $language = C4::Languages::getlanguage( $query ); +my $manual_url = Koha::Manual::get_url($refer, $language); print $query->redirect($manual_url); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref index 5aaa2a92c1..c8df929b8c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref @@ -401,3 +401,4 @@ Enhanced Content: pt_BR: Portuguese – Brazil tr: Turkish zh_TW: Chinese – Taiwan + - It will be used as a fallback value if the language used by the interface does not have an online manual version. -- 2.39.5