From 21eb5519aad6d4215b71e3b71ae4a98c05c4d935 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 30 Sep 2024 14:25:45 +0000 Subject: [PATCH] Bug 24172: [WIP alternate] Process seasons using locale when generating FIXME: I like this path, however, what we really need is a way to get localized seasons in the perl. DateTime handles months and daynames, but has no support for seasons. This patch won't work because it relies on having the languages installed and being able to translate locale 'fre' to language dir 'fr-FR' Attaching only for possible future reference. Currently we are always generating season strings as English, and translating in the templates. Compare this to handling of day/month names which are translated when generated. The numbering for a serial issue is expected to be static as printed - i.e. the French version of an issue will always say 'Hiver' while the English will always say 'Winter'. Translating depending on the interface language will make it harder for users to locate issues in a bilingual context This patch relies on bug 38034 allowing the processing of includes in process_tt If this patch is acceptable we will need a follow-up with a script to correct older serials to the correct locale in the DB - we should be able to run them through process_tt with the correct locale To test: 0 - Apply patch 1 - Make sure you have at least one language other than English installed, we're using French here 2 - Ensure translations are updated after this patch, or install the patch with the fr-FR localizer.inc 2 - Create 2 subscriptions, using numbering 'Seasonal', 1 with locale in english, 1 with locale French 3 - Ensure the prediction is in correct language for the locale 4 - Receive some issues 5 - Confirm the issues are generated with the correct locale for each subscription 6 - Ensure that changing the interface for the staff client does not affect the numering for any views Author: Nick --- C4/Serials.pm | 14 ++++-- .../prog/en/includes/localizer.inc | 43 +++++++++++++++++++ .../prog/en/modules/catalogue/detail.tt | 3 +- .../en/modules/serials/serials-collection.tt | 21 +-------- .../prog/en/modules/serials/serials-edit.tt | 5 ++- .../modules/serials/showpredictionpattern.tt | 21 +-------- .../en/modules/serials/subscription-detail.tt | 3 +- .../bootstrap/en/modules/opac-detail.tt | 5 ++- 8 files changed, 69 insertions(+), 46 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/localizer.inc diff --git a/C4/Serials.pm b/C4/Serials.pm index 4421bf35b0f..9638329ee22 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -2548,13 +2548,19 @@ sub _numeration { ? $dt->format_cldr( "LLLL" ) : $dt->strftime("%b"); } elsif ( $num_type =~ /^season$/ ) { - my @seasons= qw( Spring Summer Fall Winter ); + my $lang = C4::Languages::get_rfc4646_from_iso639($locale); $value = $value % 4; - $string = $seasons[$value]; + $string = Koha::TemplateUtils::process_tt( + q{[% PROCESS 'localizer.inc' %][%- PROCESS convert_season number => value -%]}, + { value => $value }, '', $lang + ); } elsif ( $num_type =~ /^seasonabrv$/ ) { - my @seasonsabrv= qw( Spr Sum Fal Win ); + my $lang = C4::Languages::get_rfc4646_from_iso639($locale); $value = $value % 4; - $string = $seasonsabrv[$value]; + $string = Koha::TemplateUtils::process_tt( + q{[% PROCESS 'localizer.inc' %][%- PROCESS convert_season_abrv number => value -%]}, + { value => $value }, '', $lang + ); } else { $string = $value; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/localizer.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/localizer.inc new file mode 100644 index 00000000000..8e3051c94ec --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/localizer.inc @@ -0,0 +1,43 @@ +[%~ BLOCK localize_numbering_pattern_season ~%] + [%~ IF ( matches = season.match('(.*)Spring(.*)') ) ~%] + [%~ matches.0 | html ~%]Spring[%~ matches.1 | html ~%] + [%~ ELSIF ( matches = season.match('(.*)Summer(.*)') ) ~%] + [%~ matches.0 | html ~%]Summer[%~ matches.1 | html ~%] + [%~ ELSIF ( matches = season.match('(.*)Fall(.*)') ) ~%] + [%~ matches.0 | html ~%]Fall[%~ matches.1 | html ~%] + [%~ ELSIF ( matches = season.match('(.*)Winter(.*)') ) ~%] + [%~ matches.0 | html ~%]Winter[%~ matches.1 | html ~%] + [%~ ELSIF ( matches = season.match('(.*)Spr(.*)') ) ~%] + [%~ matches.0 | html ~%]Spr[%~ matches.1 | html ~%] + [%~ ELSIF ( matches = season.match('(.*)Sum(.*)') ) ~%] + [%~ matches.0 | html ~%]Sum[%~ matches.1 | html ~%] + [%~ ELSIF ( matches = season.match('(.*)Fal(.*)') ) ~%] + [%~ matches.0 | html ~%]Fal[%~ matches.1 | html ~%] + [%~ ELSIF ( matches = season.match('(.*)Win(.*)') ) ~%] + [%~ matches.0 | html ~%]Win[%~ matches.1 | html ~%] + [%~ ELSE ~%] + [%~ season | html ~%] + [%~ END ~%] +[%~ END ~%] +[%~ BLOCK convert_season ~%] + [%~ IF ( number == 0 ) ~%] + Spring + [%~ ELSIF ( number == 1 ) ~%] + Summer + [%~ ELSIF ( number == 2 ) ~%] + Fall + [%~ ELSIF ( number == 3 ) ~%] + Winter + [%~ END ~%] +[%~ END ~%] +[%~ BLOCK convert_season_abrv ~%] + [%~ IF ( number == 0 ) ~%] + Spr + [%~ ELSIF ( number == 1 ) ~%] + Sum + [%~ ELSIF ( number == 2 ) ~%] + Fal + [%~ ELSIF ( number == 3 ) ~%] + Win + [%~ END ~%] +[%~ END ~%] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 7a00e941dcf..83e42f8adfc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -10,6 +10,7 @@ [% USE Frameworks %] [% USE Price %] [% USE TablesSettings %] +[% PROCESS 'localizer.inc' %] [% PROCESS 'i18n.inc' %] [% PROCESS 'html_helpers/tables/items/catalogue_detail.inc' %] [% SET CoverImagePlugins = KohaPlugins.get_plugins_intranet_cover_images %] @@ -534,7 +535,7 @@ [% FOREACH latestserial IN subscription.latestserials %] - [% latestserial.serialseq | html %] + [% PROCESS localize_numbering_pattern_season season => latestserial.serialseq %] [% latestserial.planneddate | $KohaDates %] [% latestserial.publisheddate | $KohaDates %] [% latestserial.publisheddatetext | html %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt index 7d4d6954f83..e758b467c0f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt @@ -5,6 +5,7 @@ [% USE HtmlTags %] [% USE KohaDates %] [% PROCESS 'i18n.inc' %] +[% PROCESS 'localizer.inc' %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] [% FILTER collapse %] @@ -283,25 +284,7 @@ [% END %] </td> <td> - [% IF ( matches = serial.serialseq.match('(.*)Spring(.*)') ) %] - [% matches.0 | html %]Spring[% matches.1 | html %] - [% ELSIF ( matches = serial.serialseq.match('(.*)Summer(.*)') ) %] - [% matches.0 | html %]Summer[% matches.1 | html %] - [% ELSIF ( matches = serial.serialseq.match('(.*)Fall(.*)') ) %] - [% matches.0 | html %]Fall[% matches.1 | html %] - [% ELSIF ( matches = serial.serialseq.match('(.*)Winter(.*)') ) %] - [% matches.0 | html %]Winter[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Spr(.*)') ) %] - [% matches.0 | html %]Spr[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Sum(.*)') ) %] - [% matches.0 | html %]Sum[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Fal(.*)') ) %] - [% matches.0 | html %]Fal[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Win(.*)') ) %] - [% matches.0 | html %]Win[% matches.1 | html %] - [% ELSE %] - [% serial.serialseq | html %] - [% END %] + [% PROCESS localize_numbering_pattern_season season => serial.serialseq %] </td> <td> [% INCLUDE 'serial-status.inc' serial = serial %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt index 644ce9d111c..fcc19e40223 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt @@ -2,6 +2,7 @@ [% USE Asset %] [% USE AuthorisedValues %] [% PROCESS 'i18n.inc' %] +[% PROCESS 'localizer.inc' %] [% INCLUDE 'doc-head-open.inc' %] <title>[% FILTER collapse %] [% t("Serial edition") | html %] @@ -159,7 +160,9 @@ $(document).ready(function() { <input type="hidden" name="biblionumber" value="[% serialslis.biblionumber | html %]" /> <input type="hidden" name="itemcount" value="[% serialslis.issuesatonce | html %]" /> <input type="hidden" name="user" value="[% serialslis.librarian | html %]" /> - Issue <input type="text" name="serialseq" id="serialseq[% serialslis.serialid | html %]" value="[% serialslis.serialseq | html %]" size="20" maxlength="100" /> + Issue <input type="text" name="serialseq" id="serialseq[% serialslis.serialid | html %]" + value="[% PROCESS localize_numbering_pattern_season season => serialslis.serialseq %]" + size="20" maxlength="100" /> </td> <td> <input type="text" name="publisheddate" value="[% serialslis.publisheddate | html %]" size="10" maxlength="15" class="flatpickr" /> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt index ea6e6ab46d3..255c90363c6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt @@ -1,4 +1,5 @@ [% USE KohaDates %] +[% PROCESS 'localizer.inc' %] <h2>Prediction pattern</h2> [% IF (not_consistent_end_date) %] <p><em>End date is not consistent with subscription length.</em></p> @@ -41,25 +42,7 @@ [% FOREACH prediction IN predictions_loop %] <tr> <td> - [% IF ( matches = prediction.number.match('(.*)Spring(.*)') ) %] - [% matches.0 | html %]Spring[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Summer(.*)') ) %] - [% matches.0 | html %]Summer[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Fall(.*)') ) %] - [% matches.0 | html %]Fall[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Winter(.*)') ) %] - [% matches.0 | html %]Winter[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Spr(.*)') ) %] - [% matches.0 | html %]Spr[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Sum(.*)') ) %] - [% matches.0 | html %]Sum[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Fal(.*)') ) %] - [% matches.0 | html %]Fal[% matches.1 | html %] - [% ELSIF ( matches = prediction.number.match('(.*)Win(.*)') ) %] - [% matches.0 | html %]Win[% matches.1 | html %] - [% ELSE %] - [% prediction.number | html %] - [% END %] + [% PROCESS localize_numbering_pattern_season season => prediction.number %] </td> <td> [% IF (prediction.publicationdate) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt index 7aed47a977f..36fcb0e262c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt @@ -10,6 +10,7 @@ [% PROCESS 'i18n.inc' %] [% SET footerjs = 1 %] [%- PROCESS 'html_helpers.inc' -%] +[% PROCESS 'localizer.inc' %] [% INCLUDE 'doc-head-open.inc' %] <title>[% FILTER collapse %] [% t("Subscription details") | html %] › @@ -270,7 +271,7 @@ [% FOREACH serialslis IN serialslist %] <tr> <td> - [% serialslis.serialseq | html %] + [% PROCESS localize_numbering_pattern_season season => serialslis.serialseq %] </td> <td> [% IF serialslis.planneddate %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index 03acede5109..c9caad342d0 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -7,6 +7,7 @@ [% USE TablesSettings %] [% USE AuthorisedValues %] [% USE KohaPlugins %] +[% PROCESS 'localizer.inc' %] [% SET TagsShowEnabled = ( ( Koha.Preference( 'TagsEnabled' ) == 1 ) && TagsShowOnDetail ) %] [% SET TagsInputEnabled = ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && ( Koha.Preference( 'TagsEnabled' ) == 1 ) && TagsInputOnDetail ) %] [% SET CoverImagePlugins = KohaPlugins.get_plugins_opac_cover_images %] @@ -763,7 +764,9 @@ <tbody> [% FOREACH latestserial IN subscription.latestserials %] <tr> - <td class="serialseq">[% latestserial.serialseq | html %]</td> + <td class="serialseq"> + [% PROCESS localize_numbering_pattern_season season => latestserial.serialseq %] + </td> <td class="publisheddate" data-order="[% latestserial.publisheddate | html %]">[% latestserial.publisheddate | $KohaDates %]</td> <td class="planneddate" data-order="[% latestserial.planneddate | html %]">[% latestserial.planneddate | $KohaDates %]</td> <td class="serial_status"> -- 2.39.5