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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2018-04-09 11:30:01 -03:00 committed by Nick Clemens
parent ac07a5074f
commit bfbc6cc941
3 changed files with 28 additions and 4 deletions
Koha
help.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences

View file

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

15
help.pl
View file

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

View file

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