Bug 18911: Add the ability to set the preferred lang for notice at the OPAC
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 17 Jun 2020 10:20:36 +0000 (12:20 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 24 Jun 2020 13:15:41 +0000 (15:15 +0200)
Patron should be allowed to modify this setting without asking a staff
member.

The setting is not configurable and cannot be hidden via a syspref.

Test plan:
- Turn the pref TranslateNotices on
- Install some languages
- Edit your messaging settings at the OPAC
=> Notice the "Preferred language for notices" dropdown list
- Select one
=> Confirm that the value is saved in DB

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt
opac/opac-messaging.pl

index d7c1161..e23499c 100644 (file)
                                     <i>Please contact a library staff member if you are unsure of your mobile service provider, or you do not see your provider in this list.</i>
                                 </li></ol>
                             [% END %]
+
+                            [% IF Koha.Preference('TranslateNotices') %]
+                                <ol>
+                                    <li>
+                                        <label for="lang">Preferred language for notices: </label>
+                                        <select id="lang" name="lang">
+                                            <option value="default">Default</option>
+                                            [% FOR language IN languages %]
+                                                [% FOR sublanguage IN language.sublanguages_loop %]
+                                                    [% IF language.plural %]
+                                                        [% IF sublanguage.rfc4646_subtag == patron_lang %]
+                                                            <option value="[% sublanguage.rfc4646_subtag | html %]" selected="selected">[% sublanguage.native_description | html %] [% sublanguage.region_description | html %] ([% sublanguage.rfc4646_subtag | html %])</option>
+                                                        [% ELSE %]
+                                                            <option value="[% sublanguage.rfc4646_subtag | html %]">[% sublanguage.native_description | html %] [% sublanguage.region_description | html %] ([% sublanguage.rfc4646_subtag | html %])</option>
+                                                        [% END %]
+                                                    [% ELSE %]
+                                                        [% IF sublanguage.rfc4646_subtag == patron_lang %]
+                                                            <option value="[% sublanguage.rfc4646_subtag | html %]" selected="selected">[% sublanguage.native_description | html %] ([% sublanguage.rfc4646_subtag | html %])</option>
+                                                        [% ELSE %]
+                                                            <option value="[% sublanguage.rfc4646_subtag | html %]">[% sublanguage.native_description | html %] ([% sublanguage.rfc4646_subtag | html %])</option>
+                                                        [% END %]
+                                                    [% END # /IF language.plural %]
+                                                [% END # /FOR sublanguage %]
+                                            [% END #/FOR language %]
+                                        </select> <!-- /#lang -->
+                                    </li>
+                                </ol>
+                            [% END #/IF Koha.Preference('TranslateNotices') %]
+
                         </fieldset>
 
                         <fieldset class="action">
index 210f944..689ce94 100755 (executable)
@@ -69,6 +69,10 @@ if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
     })->store;
 
     C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $patron->borrowernumber }, $template);
+
+    if ( C4::Context->preference('TranslateNotices') ) {
+        $patron->set({ lang => scalar $query->param('lang') })->store;
+    }
 }
 
 C4::Form::MessagingPreferences::set_form_values({ borrowernumber     => $patron->borrowernumber }, $template);
@@ -91,4 +95,12 @@ $template->param(
         }),
 );
 
+if ( C4::Context->preference('TranslateNotices') ) {
+    my $translated_languages = C4::Languages::getTranslatedLanguages( 'opac', C4::Context->preference('template') );
+    $template->param(
+        languages => $translated_languages,
+        patron_lang => $patron->lang,
+    );
+}
+
 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };