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-pref - extract translatable strings from system preferences YAML files
24 xgettext-pref [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
54 my $output = 'messages.pot';
59 'output=s' => \$output,
60 'files-from=s' => \$files_from,
62 ) or pod2usage(-verbose => 1, -exitval => 2);
65 pod2usage(-verbose => 1, -exitval => 0);
70 open(my $fh, '<', $files_from) or die "Cannot open $files_from: $!";
77 '' => Locale::PO->new(
79 -msgstr => "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 $pref = YAML::XS::LoadFile($file);
91 while ( my ($tab, $tab_content) = each %$pref ) {
92 add_po(undef, basename($file));
94 if ( ref($tab_content) eq 'ARRAY' ) {
95 add_prefs( $file, $tab, $tab_content );
97 while ( my ($section, $sysprefs) = each %$tab_content ) {
98 my $context = "$tab > $section";
99 my $msgid = sprintf('%s %s', basename($file), $section);
100 add_po($tab, $msgid);
101 add_prefs( $file, $context, $sysprefs );
107 Locale::PO->save_file_fromhash($output, $pot, 'utf8');
110 my ($file, $context, $prefs) = @_;
112 for my $pref (@$prefs) {
114 for my $element (@$pref) {
115 if ( ref($element) eq 'HASH' ) {
116 $pref_name = $element->{pref};
120 for my $element (@$pref) {
121 if ( ref($element) eq 'HASH' ) {
122 while ( my ( $key, $value ) = each(%$element) ) {
123 next unless $key eq 'choices' or $key eq 'multiple';
124 next unless ref($value) eq 'HASH';
125 for my $ckey ( keys %$value ) {
126 my $msgid = sprintf('%s#%s# %s', basename($file), $pref_name, $value->{$ckey});
127 add_po( "$context > $pref_name", $msgid );
132 my $msgid = sprintf('%s#%s# %s', basename($file), $pref_name, $element);
133 add_po( "$context > $pref_name", $msgid );
140 my ($comment, $msgid ) = @_;
142 return unless $msgid;
144 $pot->{$msgid} = Locale::PO->new(
145 -comment => $comment,