comparison tools/po4a/po4a-updatepo @ 722:082bb76417f1

Add Po4a 0.37-dev(2009-03-08)
author Dongsheng Song <dongsheng.song@gmail.com>
date Thu, 12 Mar 2009 15:43:56 +0800
parents
children
comparison
equal deleted inserted replaced
721:2180358c32c4 722:082bb76417f1
1 #! /usr/bin/env perl
2 eval 'exec perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
4
5 # pod-updatepo -- Update the po translation of POD data.
6 # $Id: po4a-updatepo,v 1.44 2009-03-07 12:33:10 nekral-guest Exp $
7 #
8 # Copyright 2002, 2003, 2004 by Martin Quinson (mquinson#debian.org)
9 #
10 # This program is free software; you can redistribute it and/or modify it
11 # under the terms of GPL (see COPYING).
12
13 =head1 NAME
14
15 po4a-updatepo - update the translation (in po format) of documentation
16
17 =head1 SYNOPSIS
18
19 po4a-updatepo -f E<lt>fmtE<gt> (-m E<lt>master.docE<gt>)+ (-p E<lt>XX.poE<gt>)+
20
21 (XX.po are the outputs, all others are inputs)
22
23 =head1 DESCRIPTION
24
25 The po4a (po for anything) project goal is to ease translations (and more
26 interestingly, the maintenance of translations) using gettext tools on
27 areas where they were not expected like documentation.
28
29 The C<po4a-updatepo> script is in charge of updating po files to make
30 them reflect the changes made to the original documentation file. For that,
31 it converts the documentation file to a pot file, and call L<msgmerge(1)>
32 on this new pot and on the provided po files.
33
34 It is possible to give more than one po file (if you want to update several
35 languages at once), and several documentation files (if you want to store
36 the translations of several documents in the same po file).
37
38 If the master document has non-ascii characters, it will convert the po files
39 to utf-8 (if they weren't already), in order to allow non-standard characters
40 in a culture independent way.
41
42 =head1 COMMAND-LINE OPTIONS
43
44 =over 4
45
46 =item -f, --format
47
48 Format of the documentation you want to handle. Use the --help-format
49 option to see the list of available formats.
50
51 =item -m, --master
52
53 File(s) containing the master document to translate.
54
55 =item -M, --master-charset
56
57 Charset of the files containing the document to translate. Note that all
58 files must have the same charset.
59
60 =item -p, --po
61
62 Po file(s) to update. If these files do not exist, they are created by
63 C<po4a-updatepo>.
64
65 =item -o, --option
66
67 Extra option(s) to pass to the format plugin and other po4a internal module.
68 Specify each option in the 'name=value' format. See the documentation of
69 each plugin for more information about the valid options and their meanings.
70
71 =item --previous
72
73 This option adds '--previous' to the options passed to msgmerge.
74 It requires gettext 0.16 or later.
75
76 =item --msgmerge-opt options
77
78 Extra options for msgmerge.
79
80 =item -h, --help
81
82 Show a short help message.
83
84 =item --help-format
85
86 List the documentation format handled by po4a.
87
88 =item -V, --version
89
90 Display the version of the script and exit.
91
92 =item -v, --verbose
93
94 Increase the verbosity of the program.
95
96 =item -d, --debug
97
98 Output some debugging information.
99
100 =back
101
102 =head1 SEE ALSO
103
104 L<po4a(7)>, L<po4a-gettextize(1)>, L<po4a-translate(1)>, L<po4a-normalize(1)>.
105
106 =head1 AUTHORS
107
108 Denis Barbier <barbier@linuxfr.org>
109 Martin Quinson (mquinson#debian.org)
110
111 =head1 COPYRIGHT AND LICENSE
112
113 Copyright 2002, 2003, 2004, 2005 by SPI, inc.
114
115 This program is free software; you may redistribute it and/or modify it
116 under the terms of GPL (see the COPYING file).
117
118 =cut
119
120 use 5.006;
121 use strict;
122 use warnings;
123
124 use Getopt::Long qw(GetOptions);
125 use Locale::Po4a::Po;
126
127 use Locale::Po4a::Chooser;
128 use Locale::Po4a::TransTractor;
129 use Locale::Po4a::Common;
130
131 use Pod::Usage qw(pod2usage);
132
133 use File::Temp;
134
135 Locale::Po4a::Common::textdomain('po4a');
136
137 sub show_version {
138 Locale::Po4a::Common::show_version("po4a-updatepo");
139 exit 0;
140 }
141
142
143 # init commandline parser
144 Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
145
146 # Parse our options
147 my (@masterfiles,@pofiles);
148 my ($help,$help_fmt,$verbose,$debug,$format,@options);
149 my $mastchar;
150 my $previous;
151 my $msgmerge_opt = "";
152 GetOptions('help|h' => \$help,
153 'help-format' => \$help_fmt,
154
155 'master|m=s' => \@masterfiles,
156 'po|p=s' => \@pofiles,
157 'format|f=s' => \$format,
158
159 'master-charset|M=s' => \$mastchar,
160
161 'option|o=s' => \@options,
162
163 'previous' => \$previous,
164 'msgmerge-opt=s' => \$msgmerge_opt,
165
166 'verbose|v' => \$verbose,
167 'debug|d' => \$debug,
168 'version|V' => \&show_version)
169 or pod2usage();
170
171 $help && pod2usage (-verbose => 1, -exitval => 0);
172 $help_fmt && Locale::Po4a::Chooser::list(0);
173 pod2usage () if scalar @masterfiles < 1 || scalar @pofiles < 1;
174
175 $msgmerge_opt .= " --previous" if $previous;
176
177 my %options = (
178 "verbose" => $verbose,
179 "debug" => $debug);
180
181 foreach (@options) {
182 if (m/^([^=]*)=(.*)$/) {
183 $options{$1}="$2";
184 } else {
185 $options{$_}=1;
186 }
187 }
188
189 # parser
190 my ($doc)=Locale::Po4a::Chooser::new($format,%options);
191
192 map { -e $_ || die wrap_msg(gettext("File %s does not exist."), $_) } @masterfiles;
193 map { die wrap_msg(gettext("po4a-updatepo can't take the input po from stdin."))
194 if $_ eq '-' && !-e '-'} @pofiles;
195
196 my ($pot_filename);
197 (undef,$pot_filename)=File::Temp->tempfile("po4a-updatepoXXXX",
198 DIR => "/tmp",
199 SUFFIX => ".pot",
200 OPEN => 0,
201 UNLINK => 0)
202 or die wrap_msg(gettext("Can't create a temporary pot file: %s"), $!);
203
204
205 print STDERR wrap_msg(gettext("Parse input files... ")) if $verbose;
206
207 $doc->{TT}{utf_mode} = 1;
208
209 $doc->process('file_in_name' => \@masterfiles,
210 'file_in_charset' => $mastchar,
211 'po_out_name' => $pot_filename,
212 'debug' => $debug,
213 'verbose' => $verbose);
214
215 print STDERR wrap_msg(gettext("done.")) if $verbose;
216
217
218 while (my $po_filename=shift @pofiles) {
219 if (-e $po_filename) {
220 print STDERR wrap_msg(gettext("Updating %s:"), $po_filename)
221 if $verbose;
222 my $cmd = "msgmerge $msgmerge_opt -U $po_filename $pot_filename";
223 system ($cmd) == 0
224 or die wrap_msg(gettext("Error while running msgmerge: %s"), $!);
225 system "msgfmt --statistics -v -o /dev/null $po_filename"
226 if $verbose;
227 } else {
228 print STDERR wrap_msg(gettext("Creating %s:"), $po_filename)
229 if $verbose;
230 system ("cp",$pot_filename,$po_filename) == 0
231 or die wrap_msg(gettext("Error while copying the po file: %s"), $!);
232 }
233 }
234
235 unlink($pot_filename);