Lines 78-83
sub new {
Link Here
|
78 |
$self->{msgmerge} = `which msgmerge`; |
78 |
$self->{msgmerge} = `which msgmerge`; |
79 |
$self->{msgfmt} = `which msgfmt`; |
79 |
$self->{msgfmt} = `which msgfmt`; |
80 |
$self->{msgcat} = `which msgcat`; |
80 |
$self->{msgcat} = `which msgcat`; |
|
|
81 |
$self->{msginit} = `which msginit`; |
81 |
$self->{xgettext} = `which xgettext`; |
82 |
$self->{xgettext} = `which xgettext`; |
82 |
$self->{sed} = `which sed`; |
83 |
$self->{sed} = `which sed`; |
83 |
$self->{po2json} = "$Bin/po2json"; |
84 |
$self->{po2json} = "$Bin/po2json"; |
Lines 85-90
sub new {
Link Here
|
85 |
chomp $self->{msgmerge}; |
86 |
chomp $self->{msgmerge}; |
86 |
chomp $self->{msgfmt}; |
87 |
chomp $self->{msgfmt}; |
87 |
chomp $self->{msgcat}; |
88 |
chomp $self->{msgcat}; |
|
|
89 |
chomp $self->{msginit}; |
88 |
chomp $self->{xgettext}; |
90 |
chomp $self->{xgettext}; |
89 |
chomp $self->{sed}; |
91 |
chomp $self->{sed}; |
90 |
|
92 |
|
Lines 480-519
sub create_tmpl {
Link Here
|
480 |
} |
482 |
} |
481 |
} |
483 |
} |
482 |
|
484 |
|
483 |
sub create_messages { |
485 |
sub locale_name { |
484 |
my $self = shift; |
486 |
my $self = shift; |
485 |
|
487 |
|
486 |
my ($language, $country) = split /-/, $self->{lang}; |
488 |
my ($language, $region, $country) = split /-/, $self->{lang}; |
|
|
489 |
$country //= $region; |
487 |
my $locale = $language; |
490 |
my $locale = $language; |
488 |
if ($country) { |
491 |
if ($country && length($country) == 2) { |
489 |
$locale .= '_' . $country; |
492 |
$locale .= '_' . $country; |
490 |
} |
493 |
} |
491 |
my $podir = "$self->{path_po}/$locale/LC_MESSAGES"; |
|
|
492 |
|
494 |
|
493 |
make_path($podir); |
495 |
return $locale; |
494 |
say "Create messages ($locale)" if $self->{verbose}; |
496 |
} |
495 |
system |
497 |
|
496 |
"$self->{cp} $self->{domain}.pot " . |
498 |
sub create_messages { |
497 |
"$podir/$self->{domain}.po"; |
499 |
my $self = shift; |
|
|
500 |
|
501 |
my $pot = "$self->{domain}.pot"; |
502 |
my $po = "$self->{path_po}/$self->{lang}-messages.po"; |
503 |
|
504 |
unless ( -f $pot ) { |
505 |
$self->extract_messages(); |
506 |
} |
507 |
|
508 |
say "Create messages ($self->{lang})" if $self->{verbose}; |
509 |
my $locale = $self->locale_name(); |
510 |
system "$self->{msginit} -i $pot -o $po -l $locale --no-translator"; |
511 |
|
512 |
# If msginit failed to correctly set Plural-Forms, set a default one |
513 |
system "$self->{sed} --in-place $po " |
514 |
. "--expression='s/Plural-Forms: nplurals=INTEGER; plural=EXPRESSION/Plural-Forms: nplurals=2; plural=(n != 1)/'"; |
498 |
} |
515 |
} |
499 |
|
516 |
|
500 |
sub update_messages { |
517 |
sub update_messages { |
501 |
my $self = shift; |
518 |
my $self = shift; |
502 |
|
519 |
|
503 |
my ($language, $country) = split /-/, $self->{lang}; |
520 |
my $pot = "$self->{domain}.pot"; |
504 |
my $locale = $language; |
521 |
my $po = "$self->{path_po}/$self->{lang}-messages.po"; |
505 |
if ($country) { |
522 |
|
506 |
$locale .= '_' . $country; |
523 |
unless ( -f $pot ) { |
|
|
524 |
$self->extract_messages(); |
507 |
} |
525 |
} |
508 |
my $podir = "$self->{path_po}/$locale/LC_MESSAGES"; |
|
|
509 |
my $pofile = "$podir/$self->{domain}.po"; |
510 |
|
526 |
|
511 |
say "Update messages ($locale)" if $self->{verbose}; |
527 |
if ( -f $po ) { |
512 |
if ( not -f $pofile ) { |
528 |
say "Update messages ($self->{lang})" if $self->{verbose}; |
513 |
say "File $pofile does not exist" if $self->{verbose}; |
529 |
system "$self->{msgmerge} -U $po $pot"; |
|
|
530 |
} else { |
514 |
$self->create_messages(); |
531 |
$self->create_messages(); |
515 |
} |
532 |
} |
516 |
system "$self->{msgmerge} -U $pofile $self->{domain}.pot"; |
|
|
517 |
} |
533 |
} |
518 |
|
534 |
|
519 |
sub extract_messages_from_templates { |
535 |
sub extract_messages_from_templates { |
Lines 524-529
sub extract_messages_from_templates {
Link Here
|
524 |
my $parser = Template::Parser->new(); |
540 |
my $parser = Template::Parser->new(); |
525 |
|
541 |
|
526 |
foreach my $file (@files) { |
542 |
foreach my $file (@files) { |
|
|
543 |
say "Extract messages from $file" if $self->{verbose}; |
527 |
my $template = read_file("$intranetdir/$file"); |
544 |
my $template = read_file("$intranetdir/$file"); |
528 |
my $data = $parser->parse($template); |
545 |
my $data = $parser->parse($template); |
529 |
my $document = PPI::Document->new(\$data->{BLOCK}); |
546 |
my $document = PPI::Document->new(\$data->{BLOCK}); |
Lines 581-586
sub extract_messages_from_templates {
Link Here
|
581 |
sub extract_messages { |
598 |
sub extract_messages { |
582 |
my $self = shift; |
599 |
my $self = shift; |
583 |
|
600 |
|
|
|
601 |
say "Extract messages into POT file" if $self->{verbose}; |
602 |
|
584 |
my $intranetdir = $self->{context}->config('intranetdir'); |
603 |
my $intranetdir = $self->{context}->config('intranetdir'); |
585 |
my @files_to_scan; |
604 |
my @files_to_scan; |
586 |
my @directories_to_scan = ('.'); |
605 |
my @directories_to_scan = ('.'); |
Lines 654-690
sub extract_messages {
Link Here
|
654 |
die "system call failed: $msgcat_cmd"; |
673 |
die "system call failed: $msgcat_cmd"; |
655 |
} |
674 |
} |
656 |
|
675 |
|
657 |
if ( -f "$Bin/$self->{domain}.pot" ) { |
676 |
my $replace_charset_cmd = "$self->{sed} --in-place " . |
658 |
my $replace_charset_cmd = "$self->{sed} --in-place " . |
677 |
"$Bin/$self->{domain}.pot " . |
659 |
"$Bin/$self->{domain}.pot " . |
678 |
"--expression='s/charset=CHARSET/charset=UTF-8/'"; |
660 |
"--expression='s/charset=CHARSET/charset=UTF-8/'"; |
679 |
if (system($replace_charset_cmd) != 0) { |
661 |
if (system($replace_charset_cmd) != 0) { |
680 |
die "system call failed: $replace_charset_cmd"; |
662 |
die "system call failed: $replace_charset_cmd"; |
|
|
663 |
} |
664 |
} else { |
665 |
say "No messages found" if $self->{verbose}; |
666 |
return; |
667 |
} |
681 |
} |
668 |
return 1; |
|
|
669 |
} |
682 |
} |
670 |
|
683 |
|
671 |
sub install_messages { |
684 |
sub install_messages { |
672 |
my ($self) = @_; |
685 |
my ($self) = @_; |
673 |
|
686 |
|
674 |
my ($language, $country) = split /-/, $self->{lang}; |
687 |
my $locale = $self->locale_name(); |
675 |
my $locale = $language; |
688 |
my $modir = "$self->{path_po}/$locale/LC_MESSAGES"; |
676 |
if ($country) { |
689 |
my $pofile = "$self->{path_po}/$self->{lang}-messages.po"; |
677 |
$locale .= '_' . $country; |
690 |
my $mofile = "$modir/$self->{domain}.mo"; |
678 |
} |
|
|
679 |
my $podir = "$self->{path_po}/$locale/LC_MESSAGES"; |
680 |
my $pofile = "$podir/$self->{domain}.po"; |
681 |
my $mofile = "$podir/$self->{domain}.mo"; |
682 |
|
691 |
|
683 |
say "Install messages ($locale)" if $self->{verbose}; |
|
|
684 |
if ( not -f $pofile ) { |
692 |
if ( not -f $pofile ) { |
685 |
say "File $pofile does not exist" if $self->{verbose}; |
|
|
686 |
$self->create_messages(); |
693 |
$self->create_messages(); |
687 |
} |
694 |
} |
|
|
695 |
say "Install messages ($locale)" if $self->{verbose}; |
696 |
make_path($modir); |
688 |
system "$self->{msgfmt} -o $mofile $pofile"; |
697 |
system "$self->{msgfmt} -o $mofile $pofile"; |
689 |
|
698 |
|
690 |
my $js_locale_data = 'var json_locale_data = {"Koha":' . `$self->{po2json} $pofile` . '};'; |
699 |
my $js_locale_data = 'var json_locale_data = {"Koha":' . `$self->{po2json} $pofile` . '};'; |
Lines 717-722
sub install {
Link Here
|
717 |
$self->install_tmpl($files) unless $self->{pref_only}; |
726 |
$self->install_tmpl($files) unless $self->{pref_only}; |
718 |
$self->install_prefs(); |
727 |
$self->install_prefs(); |
719 |
$self->install_messages(); |
728 |
$self->install_messages(); |
|
|
729 |
$self->remove_pot(); |
720 |
} |
730 |
} |
721 |
|
731 |
|
722 |
|
732 |
|
Lines 732-745
sub get_all_langs {
Link Here
|
732 |
sub update { |
742 |
sub update { |
733 |
my ($self, $files) = @_; |
743 |
my ($self, $files) = @_; |
734 |
my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs(); |
744 |
my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs(); |
735 |
my $extract_ok = $self->extract_messages(); |
|
|
736 |
for my $lang ( @langs ) { |
745 |
for my $lang ( @langs ) { |
737 |
$self->set_lang( $lang ); |
746 |
$self->set_lang( $lang ); |
738 |
$self->update_tmpl($files) unless $self->{pref_only}; |
747 |
$self->update_tmpl($files) unless $self->{pref_only}; |
739 |
$self->update_prefs(); |
748 |
$self->update_prefs(); |
740 |
$self->update_messages() if $extract_ok; |
749 |
$self->update_messages(); |
741 |
} |
750 |
} |
742 |
$self->remove_pot() if $extract_ok; |
751 |
$self->remove_pot(); |
743 |
} |
752 |
} |
744 |
|
753 |
|
745 |
|
754 |
|
Lines 748-757
sub create {
Link Here
|
748 |
return unless $self->{lang}; |
757 |
return unless $self->{lang}; |
749 |
$self->create_tmpl($files) unless $self->{pref_only}; |
758 |
$self->create_tmpl($files) unless $self->{pref_only}; |
750 |
$self->create_prefs(); |
759 |
$self->create_prefs(); |
751 |
if ($self->extract_messages()) { |
760 |
$self->create_messages(); |
752 |
$self->create_messages(); |
761 |
$self->remove_pot(); |
753 |
$self->remove_pot(); |
|
|
754 |
} |
755 |
} |
762 |
} |
756 |
|
763 |
|
757 |
|
764 |
|
758 |
- |
|
|