3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 xgettext-installer - extract translatable strings from installer YAML files
24 xgettext-installer [OPTION] [INPUTFILE]...
30 =item B<-f, --files-from=FILE>
32 get list of input files from FILE
34 =item B<-o, --output=FILE>
36 write output to the specified file
40 display this help and exit
51 use YAML::Syck qw(LoadFile);
53 $YAML::Syck::ImplicitTyping = 1;
55 my $output = 'messages.pot';
60 'output=s' => \$output,
61 'files-from=s' => \$files_from,
63 ) or pod2usage(-verbose => 1, -exitval => 2);
66 pod2usage(-verbose => 1, -exitval => 0);
71 open(my $fh, '<', $files_from) or die "Cannot open $files_from: $!";
78 '' => Locale::PO->new(
81 "Project-Id-Version: Koha\n"
82 . "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
83 . "Last-Translator: FULL NAME <EMAIL\@ADDRESS>\n"
84 . "Language-Team: Koha Translate List <koha-translate\@lists.koha-community.org>\n"
85 . "MIME-Version: 1.0\n"
86 . "Content-Type: text/plain; charset=UTF-8\n"
87 . "Content-Transfer-Encoding: 8bit\n"
91 for my $file (@files) {
92 my $yaml = LoadFile($file);
93 my @tables = @{ $yaml->{'tables'} };
96 for my $table (@tables) {
99 my $table_name = ( keys %$table )[0];
100 my @translatable = @{ $table->{$table_name}->{translatable} };
101 my @rows = @{ $table->{$table_name}->{rows} };
102 my @multiline = @{ $table->{$table_name}->{'multiline'} };
105 for my $row (@rows) {
108 for my $field (@translatable) {
109 if ( @multiline and grep { $_ eq $field } @multiline ) {
110 # multiline fields, only notices ATM
112 foreach my $line ( @{ $row->{$field} } ) {
115 # discard pure html, TT, empty
116 next if ( $line =~ /^(\s*<.*?>\s*$|^\s*\[.*?\]\s*|\s*)$/ );
119 $line =~ s/(<<.*?>>|\[\%.*?\%\]|<.*?>)/\%s/g;
121 # discard non strings
122 next if ( $line =~ /^(\s|%s|-|[[:punct:]]|\(|\))*$/ or length($line) < 2 );
123 if ( not $pot->{$line} ) {
124 my $msg = Locale::PO->new(
127 -reference => "$file:$table_name:$tablec:row:$rowc:mul:$mulc"
129 $pot->{$line} = $msg;
132 } elsif (defined $row->{$field} && length($row->{$field}) > 1 && !$pot->{ $row->{$field} }) {
133 my $msg = Locale::PO->new(
134 -msgid => $row->{$field},
136 -reference => "$file:$table_name:$tablec:row:$rowc"
138 $pot->{ $row->{$field} } = $msg;
145 for my $description ( @{ $yaml->{'description'} } ) {
147 if ( length($description) > 1 and not $pot->{$description} ) {
148 my $msg = Locale::PO->new(
149 -msgid => $description,
151 -reference => "$file:description:$desccount"
153 $pot->{$description} = $msg;
158 Locale::PO->save_file_fromhash($output, $pot);