hgbook

view tools/po4a/po4a-updatepo @ 655:65e9a18d2c7e

Shrink large images to fit page
author Dongsheng Song <dongsheng.song@gmail.com>
date Mon Mar 30 17:36:57 2009 +0800 (2009-03-30)
parents
children
line source
1 #! /usr/bin/env perl
2 eval 'exec perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
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).
13 =head1 NAME
15 po4a-updatepo - update the translation (in po format) of documentation
17 =head1 SYNOPSIS
19 po4a-updatepo -f E<lt>fmtE<gt> (-m E<lt>master.docE<gt>)+ (-p E<lt>XX.poE<gt>)+
21 (XX.po are the outputs, all others are inputs)
23 =head1 DESCRIPTION
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.
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.
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).
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.
42 =head1 COMMAND-LINE OPTIONS
44 =over 4
46 =item -f, --format
48 Format of the documentation you want to handle. Use the --help-format
49 option to see the list of available formats.
51 =item -m, --master
53 File(s) containing the master document to translate.
55 =item -M, --master-charset
57 Charset of the files containing the document to translate. Note that all
58 files must have the same charset.
60 =item -p, --po
62 Po file(s) to update. If these files do not exist, they are created by
63 C<po4a-updatepo>.
65 =item -o, --option
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.
71 =item --previous
73 This option adds '--previous' to the options passed to msgmerge.
74 It requires gettext 0.16 or later.
76 =item --msgmerge-opt options
78 Extra options for msgmerge.
80 =item -h, --help
82 Show a short help message.
84 =item --help-format
86 List the documentation format handled by po4a.
88 =item -V, --version
90 Display the version of the script and exit.
92 =item -v, --verbose
94 Increase the verbosity of the program.
96 =item -d, --debug
98 Output some debugging information.
100 =back
102 =head1 SEE ALSO
104 L<po4a(7)>, L<po4a-gettextize(1)>, L<po4a-translate(1)>, L<po4a-normalize(1)>.
106 =head1 AUTHORS
108 Denis Barbier <barbier@linuxfr.org>
109 Martin Quinson (mquinson#debian.org)
111 =head1 COPYRIGHT AND LICENSE
113 Copyright 2002, 2003, 2004, 2005 by SPI, inc.
115 This program is free software; you may redistribute it and/or modify it
116 under the terms of GPL (see the COPYING file).
118 =cut
120 use 5.006;
121 use strict;
122 use warnings;
124 use Getopt::Long qw(GetOptions);
125 use Locale::Po4a::Po;
127 use Locale::Po4a::Chooser;
128 use Locale::Po4a::TransTractor;
129 use Locale::Po4a::Common;
131 use Pod::Usage qw(pod2usage);
133 use File::Temp;
135 Locale::Po4a::Common::textdomain('po4a');
137 sub show_version {
138 Locale::Po4a::Common::show_version("po4a-updatepo");
139 exit 0;
140 }
143 # init commandline parser
144 Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
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,
155 'master|m=s' => \@masterfiles,
156 'po|p=s' => \@pofiles,
157 'format|f=s' => \$format,
159 'master-charset|M=s' => \$mastchar,
161 'option|o=s' => \@options,
163 'previous' => \$previous,
164 'msgmerge-opt=s' => \$msgmerge_opt,
166 'verbose|v' => \$verbose,
167 'debug|d' => \$debug,
168 'version|V' => \&show_version)
169 or pod2usage();
171 $help && pod2usage (-verbose => 1, -exitval => 0);
172 $help_fmt && Locale::Po4a::Chooser::list(0);
173 pod2usage () if scalar @masterfiles < 1 || scalar @pofiles < 1;
175 $msgmerge_opt .= " --previous" if $previous;
177 my %options = (
178 "verbose" => $verbose,
179 "debug" => $debug);
181 foreach (@options) {
182 if (m/^([^=]*)=(.*)$/) {
183 $options{$1}="$2";
184 } else {
185 $options{$_}=1;
186 }
187 }
189 # parser
190 my ($doc)=Locale::Po4a::Chooser::new($format,%options);
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;
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"), $!);
205 print STDERR wrap_msg(gettext("Parse input files... ")) if $verbose;
207 $doc->{TT}{utf_mode} = 1;
209 $doc->process('file_in_name' => \@masterfiles,
210 'file_in_charset' => $mastchar,
211 'po_out_name' => $pot_filename,
212 'debug' => $debug,
213 'verbose' => $verbose);
215 print STDERR wrap_msg(gettext("done.")) if $verbose;
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 }
235 unlink($pot_filename);