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
53 my $output = 'messages.pot';
58 'output=s' => \$output,
59 'files-from=s' => \$files_from,
61 ) or pod2usage(-verbose => 1, -exitval => 2);
64 pod2usage(-verbose => 1, -exitval => 0);
69 open(my $fh, '<', $files_from) or die "Cannot open $files_from: $!";
76 '' => Locale::PO->new(
79 "Project-Id-Version: Koha\n"
80 . "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
81 . "Last-Translator: FULL NAME <EMAIL\@ADDRESS>\n"
82 . "Language-Team: Koha Translate List <koha-translate\@lists.koha-community.org>\n"
83 . "MIME-Version: 1.0\n"
84 . "Content-Type: text/plain; charset=UTF-8\n"
85 . "Content-Transfer-Encoding: 8bit\n"
89 for my $file (@files) {
90 my $yaml = YAML::XS::LoadFile($file);
91 my @tables = @{ $yaml->{'tables'} };
94 for my $table (@tables) {
97 my $table_name = ( keys %$table )[0];
98 my @translatable = @{ $table->{$table_name}->{translatable} };
99 my @rows = @{ $table->{$table_name}->{rows} };
100 my @multiline = @{ $table->{$table_name}->{'multiline'} };
103 for my $row (@rows) {
106 for my $field (@translatable) {
107 if ( @multiline and grep { $_ eq $field } @multiline ) {
108 # multiline fields, only notices ATM
110 foreach my $line ( @{ $row->{$field} } ) {
114 $line =~ s/(<<.*?>>|\[\%.*?\%\]|<.*?>)/\%s/g;
116 # discard non strings
117 next if ( $line =~ /^(\s|%s|-|[[:punct:]]|\(|\))*$/ or length($line) < 2 );
118 if ( not $pot->{$line} ) {
119 my $msg = Locale::PO->new(
122 -reference => "$file:$table_name:$tablec:row:$rowc:mul:$mulc"
124 $pot->{$line} = $msg;
127 } elsif (defined $row->{$field} && length($row->{$field}) > 1 && !$pot->{ $row->{$field} }) {
128 my $msg = Locale::PO->new(
129 -msgid => $row->{$field},
131 -reference => "$file:$table_name:$tablec:row:$rowc"
133 $pot->{ $row->{$field} } = $msg;
140 for my $description ( @{ $yaml->{'description'} } ) {
142 if ( length($description) > 1 and not $pot->{$description} ) {
143 my $msg = Locale::PO->new(
144 -msgid => $description,
146 -reference => "$file:description:$desccount"
148 $pot->{$description} = $msg;
153 Locale::PO->save_file_fromhash($output, $pot, 'utf8');