Lines 50-55
use Koha::Subscription::Routinglists;
Link Here
|
50 |
use Koha::Subscriptions; |
50 |
use Koha::Subscriptions; |
51 |
use Koha::Suggestions; |
51 |
use Koha::Suggestions; |
52 |
use Koha::TemplateUtils qw( process_tt ); |
52 |
use Koha::TemplateUtils qw( process_tt ); |
|
|
53 |
use List::Util qw( first ); |
54 |
use Locale::PO; |
53 |
|
55 |
|
54 |
# Define statuses |
56 |
# Define statuses |
55 |
use constant { |
57 |
use constant { |
Lines 108-113
BEGIN {
Link Here
|
108 |
|
110 |
|
109 |
findSerialsByStatus |
111 |
findSerialsByStatus |
110 |
|
112 |
|
|
|
113 |
GetSeasonsTranslations |
111 |
); |
114 |
); |
112 |
} |
115 |
} |
113 |
|
116 |
|
Lines 861-866
sub GetNextSeq {
Link Here
|
861 |
$newinnerloop1 = $subscription->{innerloop1} || 0; |
864 |
$newinnerloop1 = $subscription->{innerloop1} || 0; |
862 |
$newinnerloop2 = $subscription->{innerloop2} || 0; |
865 |
$newinnerloop2 = $subscription->{innerloop2} || 0; |
863 |
$newinnerloop3 = $subscription->{innerloop3} || 0; |
866 |
$newinnerloop3 = $subscription->{innerloop3} || 0; |
|
|
867 |
my $translations = $subscription->{translations}; |
864 |
my %calc; |
868 |
my %calc; |
865 |
|
869 |
|
866 |
foreach (qw/X Y Z/) { |
870 |
foreach (qw/X Y Z/) { |
Lines 906-920
sub GetNextSeq {
Link Here
|
906 |
} |
910 |
} |
907 |
} |
911 |
} |
908 |
if ( $calc{'X'} ) { |
912 |
if ( $calc{'X'} ) { |
909 |
my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale ); |
913 |
my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale, $translations ); |
910 |
$calculated =~ s/\{X\}/$newlastvalue1string/g; |
914 |
$calculated =~ s/\{X\}/$newlastvalue1string/g; |
911 |
} |
915 |
} |
912 |
if ( $calc{'Y'} ) { |
916 |
if ( $calc{'Y'} ) { |
913 |
my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale ); |
917 |
my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale, $translations ); |
914 |
$calculated =~ s/\{Y\}/$newlastvalue2string/g; |
918 |
$calculated =~ s/\{Y\}/$newlastvalue2string/g; |
915 |
} |
919 |
} |
916 |
if ( $calc{'Z'} ) { |
920 |
if ( $calc{'Z'} ) { |
917 |
my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale ); |
921 |
my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale, $translations ); |
918 |
$calculated =~ s/\{Z\}/$newlastvalue3string/g; |
922 |
$calculated =~ s/\{Z\}/$newlastvalue3string/g; |
919 |
} |
923 |
} |
920 |
|
924 |
|
Lines 952-972
sub GetSeq {
Link Here
|
952 |
|
956 |
|
953 |
my $locale = $subscription->{locale}; |
957 |
my $locale = $subscription->{locale}; |
954 |
|
958 |
|
|
|
959 |
my $translations = $subscription->{translations}; |
960 |
|
955 |
my $calculated = $pattern->{numberingmethod}; |
961 |
my $calculated = $pattern->{numberingmethod}; |
956 |
|
962 |
|
957 |
my $newlastvalue1 = $subscription->{'lastvalue1'} || 0; |
963 |
my $newlastvalue1 = $subscription->{'lastvalue1'} || 0; |
958 |
$newlastvalue1 = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale ) |
964 |
$newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale, $translations) if ($pattern->{numbering1}); # reset counter if needed. |
959 |
if ( $pattern->{numbering1} ); # reset counter if needed. |
|
|
960 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
965 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
961 |
|
966 |
|
962 |
my $newlastvalue2 = $subscription->{'lastvalue2'} || 0; |
967 |
my $newlastvalue2 = $subscription->{'lastvalue2'} || 0; |
963 |
$newlastvalue2 = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale ) |
968 |
$newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale, $translations) if ($pattern->{numbering2}); # reset counter if needed. |
964 |
if ( $pattern->{numbering2} ); # reset counter if needed. |
|
|
965 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
969 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
966 |
|
970 |
|
967 |
my $newlastvalue3 = $subscription->{'lastvalue3'} || 0; |
971 |
my $newlastvalue3 = $subscription->{'lastvalue3'} || 0; |
968 |
$newlastvalue3 = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale ) |
972 |
$newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale, $translations) if ($pattern->{numbering3}); # reset counter if needed. |
969 |
if ( $pattern->{numbering3} ); # reset counter if needed. |
|
|
970 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
973 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
971 |
|
974 |
|
972 |
my $dt = dt_from_string( $subscription->{firstacquidate} ); |
975 |
my $dt = dt_from_string( $subscription->{firstacquidate} ); |
Lines 2606-2612
num_type can take :
Link Here
|
2606 |
=cut |
2609 |
=cut |
2607 |
|
2610 |
|
2608 |
sub _numeration { |
2611 |
sub _numeration { |
2609 |
my ( $value, $num_type, $locale ) = @_; |
2612 |
my ($value, $num_type, $locale, $translations) = @_; |
2610 |
$value ||= 0; |
2613 |
$value ||= 0; |
2611 |
$num_type //= ''; |
2614 |
$num_type //= ''; |
2612 |
$locale ||= 'en'; |
2615 |
$locale ||= 'en'; |
Lines 2637-2649
sub _numeration {
Link Here
|
2637 |
? $dt->format_cldr("LLLL") |
2640 |
? $dt->format_cldr("LLLL") |
2638 |
: $dt->strftime("%b"); |
2641 |
: $dt->strftime("%b"); |
2639 |
} elsif ( $num_type =~ /^season$/ ) { |
2642 |
} elsif ( $num_type =~ /^season$/ ) { |
2640 |
my @seasons = qw( Spring Summer Fall Winter ); |
|
|
2641 |
$value = $value % 4; |
2643 |
$value = $value % 4; |
2642 |
$string = $seasons[$value]; |
2644 |
$string = $translations->{seasons}->[$value]; |
2643 |
} elsif ( $num_type =~ /^seasonabrv$/ ) { |
2645 |
} elsif ( $num_type =~ /^seasonabrv$/ ) { |
2644 |
my @seasonsabrv = qw( Spr Sum Fal Win ); |
|
|
2645 |
$value = $value % 4; |
2646 |
$value = $value % 4; |
2646 |
$string = $seasonsabrv[$value]; |
2647 |
$string = $translations->{seasonsabrv}->[$value]; |
2647 |
} else { |
2648 |
} else { |
2648 |
$string = $value; |
2649 |
$string = $value; |
2649 |
} |
2650 |
} |
Lines 2713-2718
sub ReopenSubscription {
Link Here
|
2713 |
$sth->execute( EXPECTED, $subscriptionid, STOPPED ); |
2714 |
$sth->execute( EXPECTED, $subscriptionid, STOPPED ); |
2714 |
} |
2715 |
} |
2715 |
|
2716 |
|
|
|
2717 |
=head2 GetSeasonsTranslations |
2718 |
|
2719 |
Provide translations for the seasons and their abbreviations for the specified locale |
2720 |
|
2721 |
=cut |
2722 |
|
2723 |
sub GetSeasonsTranslations { |
2724 |
my ( $need_seasons, $need_seasonsabrv, $subtag ) = @_; |
2725 |
my @seasons = qw( Spring Summer Fall Winter ); |
2726 |
my @seasonsabrv = qw( Spr Sum Fal Win ); |
2727 |
my @error_messages = qw(); |
2728 |
|
2729 |
my @dirs = ( |
2730 |
C4::Context->config('intranetdir') . '/misc/translator/po', |
2731 |
C4::Context->config('intranetdir') . '/../../misc/translator/po', |
2732 |
); |
2733 |
|
2734 |
my $dir = first { -d } @dirs; |
2735 |
|
2736 |
if ($dir) { |
2737 |
my @po_paths = glob("$dir/$subtag*staff-prog.po"); |
2738 |
if (@po_paths) { |
2739 |
my $po_path = $po_paths[0]; |
2740 |
my $po_filename = ( $po_path =~ s/$dir\///gr ); |
2741 |
my $po_data = Locale::PO->load_file_ashash( $po_path, 'utf8' ); |
2742 |
|
2743 |
if ($need_seasons) { |
2744 |
my $response = _translate( $po_data, @seasons ); |
2745 |
@seasons = @{ $response->{translations} }; |
2746 |
@error_messages = |
2747 |
( @error_messages, map { sprintf( $_, $po_filename ) } @{ $response->{error_messages} } ); |
2748 |
} |
2749 |
|
2750 |
if ($need_seasonsabrv) { |
2751 |
my $response = _translate( $po_data, @seasonsabrv ); |
2752 |
@seasonsabrv = @{ $response->{translations} }; |
2753 |
@error_messages = |
2754 |
( @error_messages, map { sprintf( $_, $po_filename ) } @{ $response->{error_messages} } ); |
2755 |
} |
2756 |
} else { |
2757 |
push( |
2758 |
@error_messages, |
2759 |
"No translation file found for $subtag. Ensure that the translation files for $subtag are installed." |
2760 |
); |
2761 |
} |
2762 |
} else { |
2763 |
push( @error_messages, "The PO directory has not been found. There is a problem in your Koha installation." ); |
2764 |
} |
2765 |
|
2766 |
return { seasons => \@seasons, seasonsabrv => \@seasonsabrv, error_messages => \@error_messages }; |
2767 |
} |
2768 |
|
2716 |
=head2 subscriptionCurrentlyOnOrder |
2769 |
=head2 subscriptionCurrentlyOnOrder |
2717 |
|
2770 |
|
2718 |
$bool = subscriptionCurrentlyOnOrder( $subscriptionid ); |
2771 |
$bool = subscriptionCurrentlyOnOrder( $subscriptionid ); |
Lines 2803-2808
sub _can_do_on_subscription {
Link Here
|
2803 |
return 0; |
2856 |
return 0; |
2804 |
} |
2857 |
} |
2805 |
|
2858 |
|
|
|
2859 |
=head2 _translate |
2860 |
|
2861 |
Provide translations for the given words based on the provided data |
2862 |
|
2863 |
=cut |
2864 |
|
2865 |
sub _translate { |
2866 |
my ( $data, @words ) = @_; |
2867 |
|
2868 |
my @translations = qw(); |
2869 |
my @error_messages = qw(); |
2870 |
|
2871 |
for my $word (@words) { |
2872 |
my $regex = qr/^"$word"$|\%s$word\%s/; |
2873 |
my @msgids = grep /$regex/, keys %{$data}; |
2874 |
my $translation = ""; |
2875 |
|
2876 |
while ( ( $translation eq "" ) && ( my $msgid = shift(@msgids) ) ) { |
2877 |
next unless ( $data->{$msgid}->reference =~ /serials/ ); |
2878 |
my $msgstr = $data->{$msgid}->msgstr; |
2879 |
my @ids = split( /\%s/, $msgid ); |
2880 |
my @strs = split( /\%s/, $msgstr ); |
2881 |
|
2882 |
next unless ( scalar @ids == scalar @strs ); |
2883 |
|
2884 |
my $idx = first { $ids[$_] eq $word || $ids[$_] eq $msgid } 0 .. $#ids; |
2885 |
$translation = Locale::PO->dequote( $strs[$idx] ) if ( defined $idx ); |
2886 |
} |
2887 |
|
2888 |
if ( $translation eq "" ) { |
2889 |
push( @translations, $word ); |
2890 |
push( @error_messages, "The translation for $word doesn't exist in the file \%s" ); |
2891 |
next; |
2892 |
} |
2893 |
|
2894 |
push( @translations, $translation ); |
2895 |
} |
2896 |
|
2897 |
return { translations => \@translations, error_messages => \@error_messages }; |
2898 |
} |
2899 |
|
2806 |
=head2 findSerialsByStatus |
2900 |
=head2 findSerialsByStatus |
2807 |
|
2901 |
|
2808 |
@serials = findSerialsByStatus($status, $subscriptionid); |
2902 |
@serials = findSerialsByStatus($status, $subscriptionid); |