Lines 165-170
sub new {
Link Here
|
165 |
suffix => "-installer-MARC21.po", |
165 |
suffix => "-installer-MARC21.po", |
166 |
}; |
166 |
}; |
167 |
|
167 |
|
|
|
168 |
# EN locales sysprefs |
169 |
push @{$self->{installer}}, { |
170 |
name => "Localized sysprefs", |
171 |
dirs => [ 'installer/data/mysql/en/', ], |
172 |
suffix => "-locale-prefs.po", |
173 |
}; |
174 |
|
168 |
# EN UNIMARC YAML installer files |
175 |
# EN UNIMARC YAML installer files |
169 |
push @{$self->{installer}}, { |
176 |
push @{$self->{installer}}, { |
170 |
name => "UNIMARC YAML installer files", |
177 |
name => "UNIMARC YAML installer files", |
Lines 551-556
sub get_po_from_target {
Link Here
|
551 |
return $po; |
558 |
return $po; |
552 |
} |
559 |
} |
553 |
|
560 |
|
|
|
561 |
sub get_po_from_locale_pref { |
562 |
my $self = shift; |
563 |
my $target = shift; |
564 |
|
565 |
my $po; |
566 |
my $po_head = new Locale::PO; |
567 |
$po_head->{msgid} = "\"\""; |
568 |
$po_head->{msgstr} = "". |
569 |
"Project-Id-Version: Koha Project - Installation files\\n" . |
570 |
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\\n" . |
571 |
"Last-Translator: FULL NAME <EMAIL\@ADDRESS>\\n" . |
572 |
"Language-Team: Koha Translation Team\\n" . |
573 |
"Language: ".$self->{lang}."\\n" . |
574 |
"MIME-Version: 1.0\\n" . |
575 |
"Content-Type: text/plain; charset=UTF-8\\n" . |
576 |
"Content-Transfer-Encoding: 8bit\\n"; |
577 |
|
578 |
my @dirs = @{ $target->{dirs} }; |
579 |
my $intradir = $self->{context}->config('intranetdir'); |
580 |
for my $dir ( @dirs ) { # each dir |
581 |
opendir( my $dh, "$intradir/$dir" ) or die ("Can't open $intradir/$dir"); |
582 |
my @filelist = grep { $_ =~ m/\.yml/ } readdir($dh); # Just yaml files |
583 |
close($dh); |
584 |
for my $file ( @filelist ) { # each file |
585 |
my $yaml = LoadFile( "$intradir/$dir/$file" ); |
586 |
my @tables = @{ $yaml->{'tables'} }; |
587 |
my $tablec; |
588 |
for my $table ( @tables ) { # each table |
589 |
$tablec++; |
590 |
my $table_name = ( keys %$table )[0]; |
591 |
my @translatable = @{ $table->{$table_name}->{translatable} }; |
592 |
my @rows = @{ $table->{$table_name}->{rows} }; |
593 |
my @comments; |
594 |
@comments = @{ $table->{$table_name}->{'comments'} } if ( $table->{$table_name}->{'comments'} ); |
595 |
my $rowc; |
596 |
for my $row ( @rows ) { # each row |
597 |
$rowc++; |
598 |
for my $field ( @translatable ) { # each field |
599 |
my $automatic; |
600 |
$automatic = "Use this to SET sysprefs\n" . join "\n", map { "$_: $row->{$_}" } @comments if ( @comments ); |
601 |
if ( defined $row->{$field} and not $po->{ "$row->{variable}# ".$row->{$field} } ) { |
602 |
my $msg = new Locale::PO( |
603 |
-msgid => "$row->{variable}# ".$row->{$field}, -msgstr => "$row->{$field}", |
604 |
-reference => "$dir/$file:$table_name:$tablec:row:$rowc" ); |
605 |
$msg->automatic($automatic) if ( $automatic ); |
606 |
$msg->fuzzy(1); |
607 |
$po->{ "$row->{variable}# ".$row->{$field} } = $msg; |
608 |
} |
609 |
} |
610 |
} |
611 |
} |
612 |
} |
613 |
} |
614 |
$po->{''} = $po_head if ( $po ); |
615 |
|
616 |
return $po; |
617 |
} |
618 |
|
554 |
sub create_installer { |
619 |
sub create_installer { |
555 |
my $self = shift; |
620 |
my $self = shift; |
556 |
return unless ( $self->{installer} ); |
621 |
return unless ( $self->{installer} ); |
Lines 567-573
sub create_installer {
Link Here
|
567 |
} |
632 |
} |
568 |
|
633 |
|
569 |
for my $target ( @targets ) { |
634 |
for my $target ( @targets ) { |
570 |
my $po = get_po_from_target( $self, $target ); |
635 |
my $po = ( $target->{suffix} =~ /locale-prefs/ ) ? get_po_from_locale_pref( $self, $target ) : get_po_from_target( $self, $target ); |
571 |
# create output file only if there is something to write |
636 |
# create output file only if there is something to write |
572 |
if ( $po ) { |
637 |
if ( $po ) { |
573 |
my $po_file = $self->po_filename( $target->{suffix} ); |
638 |
my $po_file = $self->po_filename( $target->{suffix} ); |
Lines 587-593
sub update_installer {
Link Here
|
587 |
|
652 |
|
588 |
for my $target ( @targets ) { |
653 |
for my $target ( @targets ) { |
589 |
return unless ( -e $self->po_filename( $target->{suffix} ) ); |
654 |
return unless ( -e $self->po_filename( $target->{suffix} ) ); |
590 |
my $po = get_po_from_target( $self, $target ); |
655 |
my $po = ( $target->{suffix} =~ /locale-pref/ ) ? get_po_from_locale_pref( $self, $target ) : get_po_from_target( $self, $target ); |
591 |
# update file only if there is something to update |
656 |
# update file only if there is something to update |
592 |
if ( $po ) { |
657 |
if ( $po ) { |
593 |
my ( $fh, $po_temp ) = tempfile(); |
658 |
my ( $fh, $po_temp ) = tempfile(); |
Lines 608-613
sub translate_yaml {
Link Here
|
608 |
my $target = shift; |
673 |
my $target = shift; |
609 |
my $srcyml = shift; |
674 |
my $srcyml = shift; |
610 |
|
675 |
|
|
|
676 |
my $pref = ( $target->{suffix} =~ /locale-pref/ ) ? 1 : 0; |
677 |
|
611 |
my $po_file = $self->po_filename( $target->{suffix} ); |
678 |
my $po_file = $self->po_filename( $target->{suffix} ); |
612 |
return $srcyml unless ( -e $po_file ); |
679 |
return $srcyml unless ( -e $po_file ); |
613 |
|
680 |
|
Lines 654-660
sub translate_yaml {
Link Here
|
654 |
} |
721 |
} |
655 |
} else { |
722 |
} else { |
656 |
next unless defined $row->{$field}; # next if null value |
723 |
next unless defined $row->{$field}; # next if null value |
657 |
my $po = $po_ref->{"\"$row->{$field}\""}; # quoted key |
724 |
my $key = ( $pref ) ? $row->{variable}."# ".$row->{$field} : $row->{$field}; |
|
|
725 |
$key =~ s/"/\\"/g; |
726 |
my $po = $po_ref->{"\"$key\""}; |
658 |
if ( $po and not defined( $po->fuzzy() ) # not fuzzy |
727 |
if ( $po and not defined( $po->fuzzy() ) # not fuzzy |
659 |
and length( $po->msgid() ) > 2 # not empty msgid |
728 |
and length( $po->msgid() ) > 2 # not empty msgid |
660 |
and length( $po->msgstr() ) > 2 ) { # not empty msgstr |
729 |
and length( $po->msgstr() ) > 2 ) { # not empty msgstr |
Lines 699-705
sub install_installer {
Link Here
|
699 |
make_path("$intradir/$tdir"); |
768 |
make_path("$intradir/$tdir"); |
700 |
|
769 |
|
701 |
opendir( my $dh, "$intradir/$dir" ) or die ("Can't open $intradir/$dir"); |
770 |
opendir( my $dh, "$intradir/$dir" ) or die ("Can't open $intradir/$dir"); |
702 |
my @files = grep { ! /^\.+$/ } readdir($dh); |
771 |
my @files = grep { $_ =~ m/\.yml/ } readdir($dh); |
703 |
close($dh); |
772 |
close($dh); |
704 |
|
773 |
|
705 |
for my $file ( @files ) { |
774 |
for my $file ( @files ) { |
706 |
- |
|
|