Lines 48-53
use Koha::Subscription::Histories;
Link Here
|
48 |
use Koha::Subscriptions; |
48 |
use Koha::Subscriptions; |
49 |
use Koha::Suggestions; |
49 |
use Koha::Suggestions; |
50 |
use Koha::TemplateUtils qw( process_tt ); |
50 |
use Koha::TemplateUtils qw( process_tt ); |
|
|
51 |
use List::Util qw( first ); |
52 |
use Locale::PO; |
51 |
|
53 |
|
52 |
# Define statuses |
54 |
# Define statuses |
53 |
use constant { |
55 |
use constant { |
Lines 105-110
BEGIN {
Link Here
|
105 |
|
107 |
|
106 |
findSerialsByStatus |
108 |
findSerialsByStatus |
107 |
|
109 |
|
|
|
110 |
GetSeasonsTranslations |
108 |
); |
111 |
); |
109 |
} |
112 |
} |
110 |
|
113 |
|
Lines 859-864
sub GetNextSeq {
Link Here
|
859 |
$newinnerloop1 = $subscription->{innerloop1} || 0; |
862 |
$newinnerloop1 = $subscription->{innerloop1} || 0; |
860 |
$newinnerloop2 = $subscription->{innerloop2} || 0; |
863 |
$newinnerloop2 = $subscription->{innerloop2} || 0; |
861 |
$newinnerloop3 = $subscription->{innerloop3} || 0; |
864 |
$newinnerloop3 = $subscription->{innerloop3} || 0; |
|
|
865 |
my $translations = $subscription->{translations}; |
862 |
my %calc; |
866 |
my %calc; |
863 |
foreach(qw/X Y Z/) { |
867 |
foreach(qw/X Y Z/) { |
864 |
$calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/); |
868 |
$calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/); |
Lines 897-911
sub GetNextSeq {
Link Here
|
897 |
} |
901 |
} |
898 |
} |
902 |
} |
899 |
if($calc{'X'}) { |
903 |
if($calc{'X'}) { |
900 |
my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale ); |
904 |
my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale, $translations ); |
901 |
$calculated =~ s/\{X\}/$newlastvalue1string/g; |
905 |
$calculated =~ s/\{X\}/$newlastvalue1string/g; |
902 |
} |
906 |
} |
903 |
if($calc{'Y'}) { |
907 |
if($calc{'Y'}) { |
904 |
my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale ); |
908 |
my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale, $translations ); |
905 |
$calculated =~ s/\{Y\}/$newlastvalue2string/g; |
909 |
$calculated =~ s/\{Y\}/$newlastvalue2string/g; |
906 |
} |
910 |
} |
907 |
if($calc{'Z'}) { |
911 |
if($calc{'Z'}) { |
908 |
my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale ); |
912 |
my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale, $translations ); |
909 |
$calculated =~ s/\{Z\}/$newlastvalue3string/g; |
913 |
$calculated =~ s/\{Z\}/$newlastvalue3string/g; |
910 |
} |
914 |
} |
911 |
|
915 |
|
Lines 934-951
sub GetSeq {
Link Here
|
934 |
|
938 |
|
935 |
my $locale = $subscription->{locale}; |
939 |
my $locale = $subscription->{locale}; |
936 |
|
940 |
|
|
|
941 |
my $translations = $subscription->{translations}; |
942 |
|
937 |
my $calculated = $pattern->{numberingmethod}; |
943 |
my $calculated = $pattern->{numberingmethod}; |
938 |
|
944 |
|
939 |
my $newlastvalue1 = $subscription->{'lastvalue1'} || 0; |
945 |
my $newlastvalue1 = $subscription->{'lastvalue1'} || 0; |
940 |
$newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale) if ($pattern->{numbering1}); # reset counter if needed. |
946 |
$newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale, $translations) if ($pattern->{numbering1}); # reset counter if needed. |
941 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
947 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
942 |
|
948 |
|
943 |
my $newlastvalue2 = $subscription->{'lastvalue2'} || 0; |
949 |
my $newlastvalue2 = $subscription->{'lastvalue2'} || 0; |
944 |
$newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale) if ($pattern->{numbering2}); # reset counter if needed. |
950 |
$newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale, $translations) if ($pattern->{numbering2}); # reset counter if needed. |
945 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
951 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
946 |
|
952 |
|
947 |
my $newlastvalue3 = $subscription->{'lastvalue3'} || 0; |
953 |
my $newlastvalue3 = $subscription->{'lastvalue3'} || 0; |
948 |
$newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale) if ($pattern->{numbering3}); # reset counter if needed. |
954 |
$newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale, $translations) if ($pattern->{numbering3}); # reset counter if needed. |
949 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
955 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
950 |
return $calculated; |
956 |
return $calculated; |
951 |
} |
957 |
} |
Lines 2501-2507
num_type can take :
Link Here
|
2501 |
=cut |
2507 |
=cut |
2502 |
|
2508 |
|
2503 |
sub _numeration { |
2509 |
sub _numeration { |
2504 |
my ($value, $num_type, $locale) = @_; |
2510 |
my ($value, $num_type, $locale, $translations) = @_; |
2505 |
$value ||= 0; |
2511 |
$value ||= 0; |
2506 |
$num_type //= ''; |
2512 |
$num_type //= ''; |
2507 |
$locale ||= 'en'; |
2513 |
$locale ||= 'en'; |
Lines 2529-2541
sub _numeration {
Link Here
|
2529 |
? $dt->format_cldr( "LLLL" ) |
2535 |
? $dt->format_cldr( "LLLL" ) |
2530 |
: $dt->strftime("%b"); |
2536 |
: $dt->strftime("%b"); |
2531 |
} elsif ( $num_type =~ /^season$/ ) { |
2537 |
} elsif ( $num_type =~ /^season$/ ) { |
2532 |
my @seasons= qw( Spring Summer Fall Winter ); |
|
|
2533 |
$value = $value % 4; |
2538 |
$value = $value % 4; |
2534 |
$string = $seasons[$value]; |
2539 |
$string = $translations->{seasons}->[$value]; |
2535 |
} elsif ( $num_type =~ /^seasonabrv$/ ) { |
2540 |
} elsif ( $num_type =~ /^seasonabrv$/ ) { |
2536 |
my @seasonsabrv= qw( Spr Sum Fal Win ); |
|
|
2537 |
$value = $value % 4; |
2541 |
$value = $value % 4; |
2538 |
$string = $seasonsabrv[$value]; |
2542 |
$string = $translations->{seasonsabrv}->[$value]; |
2539 |
} else { |
2543 |
} else { |
2540 |
$string = $value; |
2544 |
$string = $value; |
2541 |
} |
2545 |
} |
Lines 2597-2602
sub ReopenSubscription {
Link Here
|
2597 |
$sth->execute( EXPECTED, $subscriptionid, STOPPED ); |
2601 |
$sth->execute( EXPECTED, $subscriptionid, STOPPED ); |
2598 |
} |
2602 |
} |
2599 |
|
2603 |
|
|
|
2604 |
=head2 GetSeasonsTranslations |
2605 |
|
2606 |
Provide translations for the seasons and their abbreviations for the specified locale |
2607 |
|
2608 |
=cut |
2609 |
|
2610 |
sub GetSeasonsTranslations { |
2611 |
my ( $need_seasons, $need_seasonsabrv, $subtag ) = @_; |
2612 |
my @seasons = qw( Spring Summer Fall Winter ); |
2613 |
my @seasonsabrv = qw( Spr Sum Fal Win ); |
2614 |
my @error_messages = qw(); |
2615 |
|
2616 |
my @dirs = ( |
2617 |
C4::Context->config('intranetdir') . '/misc/translator/po', |
2618 |
C4::Context->config('intranetdir') . '/../../misc/translator/po', |
2619 |
); |
2620 |
|
2621 |
my $dir = first { -d } @dirs; |
2622 |
|
2623 |
if ($dir) { |
2624 |
my @po_paths = glob("$dir/$subtag*staff-prog.po"); |
2625 |
if (@po_paths) { |
2626 |
my $po_path = $po_paths[0]; |
2627 |
my $po_filename = ( $po_path =~ s/$dir\///gr ); |
2628 |
my $po_data = Locale::PO->load_file_ashash( $po_path, 'utf8' ); |
2629 |
|
2630 |
if ($need_seasons) { |
2631 |
my $response = _translate( $po_data, @seasons ); |
2632 |
@seasons = @{ $response->{translations} }; |
2633 |
@error_messages = |
2634 |
( @error_messages, map { sprintf( $_, $po_filename ) } @{ $response->{error_messages} } ); |
2635 |
} |
2636 |
|
2637 |
if ($need_seasonsabrv) { |
2638 |
my $response = _translate( $po_data, @seasonsabrv ); |
2639 |
@seasonsabrv = @{ $response->{translations} }; |
2640 |
@error_messages = |
2641 |
( @error_messages, map { sprintf( $_, $po_filename ) } @{ $response->{error_messages} } ); |
2642 |
} |
2643 |
} else { |
2644 |
push( |
2645 |
@error_messages, |
2646 |
"No translation file found for $subtag. Ensure that the translation files for $subtag are installed." |
2647 |
); |
2648 |
} |
2649 |
} else { |
2650 |
push( @error_messages, "The PO directory has not been found. There is a problem in your Koha installation." ); |
2651 |
} |
2652 |
|
2653 |
return { seasons => \@seasons, seasonsabrv => \@seasonsabrv, error_messages => \@error_messages }; |
2654 |
} |
2655 |
|
2600 |
=head2 subscriptionCurrentlyOnOrder |
2656 |
=head2 subscriptionCurrentlyOnOrder |
2601 |
|
2657 |
|
2602 |
$bool = subscriptionCurrentlyOnOrder( $subscriptionid ); |
2658 |
$bool = subscriptionCurrentlyOnOrder( $subscriptionid ); |
Lines 2691-2696
sub _can_do_on_subscription {
Link Here
|
2691 |
return 0; |
2747 |
return 0; |
2692 |
} |
2748 |
} |
2693 |
|
2749 |
|
|
|
2750 |
=head2 _translate |
2751 |
|
2752 |
Provide translations for the given words based on the provided data |
2753 |
|
2754 |
=cut |
2755 |
|
2756 |
sub _translate { |
2757 |
my ( $data, @words ) = @_; |
2758 |
|
2759 |
my @translations = qw(); |
2760 |
my @error_messages = qw(); |
2761 |
|
2762 |
for my $word (@words) { |
2763 |
my $regex = qr/^"$word"$|\%s$word\%s/; |
2764 |
my @msgids = grep /$regex/, keys %{$data}; |
2765 |
my $translation = ""; |
2766 |
|
2767 |
while ( ( $translation eq "" ) && ( my $msgid = shift(@msgids) ) ) { |
2768 |
next unless ( $data->{$msgid}->reference =~ /serials/ ); |
2769 |
my $msgstr = $data->{$msgid}->msgstr; |
2770 |
my @ids = split( /\%s/, $msgid ); |
2771 |
my @strs = split( /\%s/, $msgstr ); |
2772 |
|
2773 |
next unless ( scalar @ids == scalar @strs ); |
2774 |
|
2775 |
my $idx = first { $ids[$_] eq $word || $ids[$_] eq $msgid } 0 .. $#ids; |
2776 |
$translation = Locale::PO->dequote( $strs[$idx] ) if ( defined $idx ); |
2777 |
} |
2778 |
|
2779 |
if ( $translation eq "" ) { |
2780 |
push( @translations, $word ); |
2781 |
push( @error_messages, "The translation for $word doesn't exist in the file \%s" ); |
2782 |
next; |
2783 |
} |
2784 |
|
2785 |
push( @translations, $translation ); |
2786 |
} |
2787 |
|
2788 |
return { translations => \@translations, error_messages => \@error_messages }; |
2789 |
} |
2790 |
|
2694 |
=head2 findSerialsByStatus |
2791 |
=head2 findSerialsByStatus |
2695 |
|
2792 |
|
2696 |
@serials = findSerialsByStatus($status, $subscriptionid); |
2793 |
@serials = findSerialsByStatus($status, $subscriptionid); |