Bug 19817: Use the language from the interface if valid
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 9 Apr 2018 14:30:01 +0000 (11:30 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 6 Sep 2018 17:32:28 +0000 (17:32 +0000)
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>

Koha/Manual.pm
help.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref

index fe0c3a2..cab6156 100644 (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} );
 }
 
diff --git a/help.pl b/help.pl
index df94649..b39c577 100755 (executable)
--- a/help.pl
+++ b/help.pl
 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);
index 5aaa2a9..c8df929 100644 (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.