rev |
line source |
dongsheng@623
|
1 #! /usr/bin/env perl
|
dongsheng@623
|
2 eval 'exec perl -S $0 ${1+"$@"}'
|
dongsheng@623
|
3 if $running_under_some_shell;
|
dongsheng@623
|
4
|
dongsheng@623
|
5 # po4a-translate -- translate doc files using a message catalog(ie, po file)
|
dongsheng@623
|
6 # $Id: po4a-translate,v 1.41 2009-03-07 12:33:10 nekral-guest Exp $
|
dongsheng@623
|
7 #
|
dongsheng@623
|
8 # Copyright 2002, 2003, 2004 by Martin Quinson (mquinson#debian.org)
|
dongsheng@623
|
9 #
|
dongsheng@623
|
10 # This program is free software; you can redistribute it and/or modify it
|
dongsheng@623
|
11 # under the terms of GPL (see COPYING).
|
dongsheng@623
|
12
|
dongsheng@623
|
13 =head1 NAME
|
dongsheng@623
|
14
|
dongsheng@623
|
15 po4a-translate - convert a po file back to documentation format
|
dongsheng@623
|
16
|
dongsheng@623
|
17 =head1 SYNOPSIS
|
dongsheng@623
|
18
|
dongsheng@623
|
19 po4a-translate -f E<lt>fmtE<gt> -m E<lt>master.docE<gt> -p E<lt>XX.poE<gt> -l E<lt>XX.docE<gt>
|
dongsheng@623
|
20
|
dongsheng@623
|
21 (XX.doc is the output, all others are inputs)
|
dongsheng@623
|
22
|
dongsheng@623
|
23 =head1 DESCRIPTION
|
dongsheng@623
|
24
|
dongsheng@623
|
25 The po4a (po for anything) project goal is to ease translations (and more
|
dongsheng@623
|
26 interestingly, the maintenance of translations) using gettext tools on
|
dongsheng@623
|
27 areas where they were not expected like documentation.
|
dongsheng@623
|
28
|
dongsheng@623
|
29 The C<po4a-translate> script is in charge of converting the translation
|
dongsheng@623
|
30 (which was done in a po file) under the documentation format back. The
|
dongsheng@623
|
31 provided C<po> file should be the translation of the C<pot> file which were
|
dongsheng@623
|
32 produced by po4a-gettextize(1).
|
dongsheng@623
|
33
|
dongsheng@623
|
34 =head1 OPTIONS
|
dongsheng@623
|
35
|
dongsheng@623
|
36 =over 4
|
dongsheng@623
|
37
|
dongsheng@623
|
38 =item -f, --format
|
dongsheng@623
|
39
|
dongsheng@623
|
40 Format of the documentation you want to handle. Use the --help-format
|
dongsheng@623
|
41 option to see the list of available formats.
|
dongsheng@623
|
42
|
dongsheng@623
|
43 =item -a, --addendum
|
dongsheng@623
|
44
|
dongsheng@623
|
45 Add a file to the resulting file (to put translator's name or a section
|
dongsheng@623
|
46 "About this translation", for example). The first line of the file to insert
|
dongsheng@623
|
47 should be a PO4A header indicating where it should be added (see section
|
dongsheng@623
|
48 I<HOWTO add extra text to translations> in po4a(7)).
|
dongsheng@623
|
49
|
dongsheng@623
|
50 =item -A, --addendum-charset
|
dongsheng@623
|
51
|
dongsheng@623
|
52 Charset of the addenda. Note that all the addenda should be in the same
|
dongsheng@623
|
53 charset.
|
dongsheng@623
|
54
|
dongsheng@623
|
55 =item -m, --master
|
dongsheng@623
|
56
|
dongsheng@623
|
57 File containing the master document to translate.
|
dongsheng@623
|
58
|
dongsheng@623
|
59 =item -M, --master-charset
|
dongsheng@623
|
60
|
dongsheng@623
|
61 Charset of the file containing the document to translate.
|
dongsheng@623
|
62
|
dongsheng@623
|
63 =item -l, --localized
|
dongsheng@623
|
64
|
dongsheng@623
|
65 File where the localized (translated) document should be written.
|
dongsheng@623
|
66
|
dongsheng@623
|
67 =item -L, --localized-charset
|
dongsheng@623
|
68
|
dongsheng@623
|
69 Charset of the file containing the localized document.
|
dongsheng@623
|
70
|
dongsheng@623
|
71 =item -p, --po
|
dongsheng@623
|
72
|
dongsheng@623
|
73 File from which the message catalog should be read.
|
dongsheng@623
|
74
|
dongsheng@623
|
75 =item -o, --option
|
dongsheng@623
|
76
|
dongsheng@623
|
77 Extra option(s) to pass to the format plugin. Specify each option in the
|
dongsheng@623
|
78 'name=value' format. See the documentation of each plugin for more
|
dongsheng@623
|
79 information about the valid options and their meanings.
|
dongsheng@623
|
80
|
dongsheng@623
|
81 =item -k, --keep
|
dongsheng@623
|
82
|
dongsheng@623
|
83 Minimal threshold for translation percentage to keep (ie, write) the
|
dongsheng@623
|
84 resulting file (default: 80). Ie, by default, files have to be translated
|
dongsheng@623
|
85 at at least 80% to get written.
|
dongsheng@623
|
86
|
dongsheng@623
|
87 =item -w, --width
|
dongsheng@623
|
88
|
dongsheng@623
|
89 Column at which we should wrap the resulting file.
|
dongsheng@623
|
90
|
dongsheng@623
|
91 =item -h, --help
|
dongsheng@623
|
92
|
dongsheng@623
|
93 Show a short help message.
|
dongsheng@623
|
94
|
dongsheng@623
|
95 =item --help-format
|
dongsheng@623
|
96
|
dongsheng@623
|
97 List the documentation format understood by po4a.
|
dongsheng@623
|
98
|
dongsheng@623
|
99 =item -V, --version
|
dongsheng@623
|
100
|
dongsheng@623
|
101 Display the version of the script and exit.
|
dongsheng@623
|
102
|
dongsheng@623
|
103 =item -v, --verbose
|
dongsheng@623
|
104
|
dongsheng@623
|
105 Increase the verbosity of the program.
|
dongsheng@623
|
106
|
dongsheng@623
|
107 =item -d, --debug
|
dongsheng@623
|
108
|
dongsheng@623
|
109 Output some debugging information.
|
dongsheng@623
|
110
|
dongsheng@623
|
111 =back
|
dongsheng@623
|
112
|
dongsheng@623
|
113 =head1 Adding content (beside translations) to generated files
|
dongsheng@623
|
114
|
dongsheng@623
|
115 To add some extra content to the generated document beside what you
|
dongsheng@623
|
116 translated (like the name of the translator, or a "about this translation"
|
dongsheng@623
|
117 section), you should use the C<--addendum> option.
|
dongsheng@623
|
118
|
dongsheng@623
|
119 The first line of the addendum must be a header indicating where to put
|
dongsheng@623
|
120 it in the document (it can be before or after a given part of the
|
dongsheng@623
|
121 document). The rest of the file will be added verbatim to the resulting
|
dongsheng@623
|
122 file without further processing.
|
dongsheng@623
|
123
|
dongsheng@623
|
124 Note that if po4a-translate fails to add one of the given files, it discards
|
dongsheng@623
|
125 the whole translation (because the missing file could be the one indicating
|
dongsheng@623
|
126 the author, what would prevent the users to contact him to report bugs in
|
dongsheng@623
|
127 the translation).
|
dongsheng@623
|
128
|
dongsheng@623
|
129 The header has a pretty rigid syntax. For more information on how to use
|
dongsheng@623
|
130 this feature and how it works, please refer to the po4a(7) man page.
|
dongsheng@623
|
131
|
dongsheng@623
|
132 =head1 SEE ALSO
|
dongsheng@623
|
133
|
dongsheng@623
|
134 L<po4a(7)>, L<po4a-gettextize(1)>, L<po4a-updatepo(1)>, L<po4a-normalize(1)>.
|
dongsheng@623
|
135
|
dongsheng@623
|
136
|
dongsheng@623
|
137 =head1 AUTHORS
|
dongsheng@623
|
138
|
dongsheng@623
|
139 Denis Barbier <barbier@linuxfr.org>
|
dongsheng@623
|
140 Martin Quinson (mquinson#debian.org)
|
dongsheng@623
|
141
|
dongsheng@623
|
142 =head1 COPYRIGHT AND LICENSE
|
dongsheng@623
|
143
|
dongsheng@623
|
144 Copyright 2002, 2003, 2004 by SPI, inc.
|
dongsheng@623
|
145
|
dongsheng@623
|
146 This program is free software; you may redistribute it and/or modify it
|
dongsheng@623
|
147 under the terms of GPL (see the COPYING file).
|
dongsheng@623
|
148
|
dongsheng@623
|
149 =cut
|
dongsheng@623
|
150
|
dongsheng@623
|
151 use 5.006;
|
dongsheng@623
|
152 use strict;
|
dongsheng@623
|
153 use warnings;
|
dongsheng@623
|
154
|
dongsheng@623
|
155 use Locale::Po4a::Chooser;
|
dongsheng@623
|
156 use Locale::Po4a::TransTractor;
|
dongsheng@623
|
157 use Locale::Po4a::Common;
|
dongsheng@623
|
158
|
dongsheng@623
|
159 use Pod::Usage qw(pod2usage);
|
dongsheng@623
|
160 use Getopt::Long qw(GetOptions);
|
dongsheng@623
|
161
|
dongsheng@623
|
162 Locale::Po4a::Common::textdomain("po4a");
|
dongsheng@623
|
163
|
dongsheng@623
|
164 sub show_version {
|
dongsheng@623
|
165 Locale::Po4a::Common::show_version("po4a-translate");
|
dongsheng@623
|
166 exit 0;
|
dongsheng@623
|
167 }
|
dongsheng@623
|
168
|
dongsheng@623
|
169
|
dongsheng@623
|
170 Getopt::Long::Configure('no_auto_abbrev','no_ignore_case');
|
dongsheng@623
|
171 my ($outfile,$width,$threshold)=('-',80,80);
|
dongsheng@623
|
172 my ($help,$help_fmt,@verbose,$debug,@addfiles,$format,@options);
|
dongsheng@623
|
173 my ($master_filename,$po_filename);
|
dongsheng@623
|
174 my ($mastchar,$locchar,$addchar);
|
dongsheng@623
|
175 GetOptions(
|
dongsheng@623
|
176 'help|h' => \$help,
|
dongsheng@623
|
177 'help-format' => \$help_fmt,
|
dongsheng@623
|
178
|
dongsheng@623
|
179 'master|m=s' => \$master_filename,
|
dongsheng@623
|
180 'localized|l=s' => \$outfile,
|
dongsheng@623
|
181 'po|p=s' => \$po_filename,
|
dongsheng@623
|
182 'addendum|a=s' => \@addfiles,
|
dongsheng@623
|
183 'format|f=s' => \$format,
|
dongsheng@623
|
184
|
dongsheng@623
|
185 'master-charset|M=s' => \$mastchar,
|
dongsheng@623
|
186 'localized-charset|L=s' => \$locchar,
|
dongsheng@623
|
187 'addendum-charset|A=s' => \$addchar,
|
dongsheng@623
|
188
|
dongsheng@623
|
189 'option|o=s' => \@options,
|
dongsheng@623
|
190
|
dongsheng@623
|
191 'width|w=s' => \$width,
|
dongsheng@623
|
192 'verbose|v' => \@verbose,
|
dongsheng@623
|
193 'debug|d' => \$debug,
|
dongsheng@623
|
194 'keep|k=s' => \$threshold,
|
dongsheng@623
|
195
|
dongsheng@623
|
196 'version|V' => \&show_version
|
dongsheng@623
|
197 ) or pod2usage();
|
dongsheng@623
|
198
|
dongsheng@623
|
199 $help && pod2usage(-verbose => 1, -exitval => 0);
|
dongsheng@623
|
200 $help_fmt && Locale::Po4a::Chooser::list(0);
|
dongsheng@623
|
201
|
dongsheng@623
|
202 (defined($master_filename) && length($master_filename))||pod2usage();
|
dongsheng@623
|
203 (defined($po_filename) && length($po_filename)) ||pod2usage();
|
dongsheng@623
|
204 -e $master_filename || die wrap_msg(gettext("File %s does not exist."), $master_filename);
|
dongsheng@623
|
205 -e $po_filename || die wrap_msg(gettext("File %s does not exist."), $po_filename);
|
dongsheng@623
|
206
|
dongsheng@623
|
207 my (@pos,@masters);
|
dongsheng@623
|
208 push @pos,$po_filename;
|
dongsheng@623
|
209 push @masters,$master_filename;
|
dongsheng@623
|
210
|
dongsheng@623
|
211 my %options = (
|
dongsheng@623
|
212 "verbose" => scalar @verbose,
|
dongsheng@623
|
213 "debug" => $debug);
|
dongsheng@623
|
214
|
dongsheng@623
|
215 foreach (@options) {
|
dongsheng@623
|
216 if (m/^([^=]*)=(.*)$/) {
|
dongsheng@623
|
217 $options{$1}="$2";
|
dongsheng@623
|
218 } else {
|
dongsheng@623
|
219 $options{$_}=1;
|
dongsheng@623
|
220 }
|
dongsheng@623
|
221 }
|
dongsheng@623
|
222 # parser
|
dongsheng@623
|
223 my $doc=Locale::Po4a::Chooser::new($format,%options);
|
dongsheng@623
|
224
|
dongsheng@623
|
225
|
dongsheng@623
|
226 # Prepare the document to be used as translator, but not parser
|
dongsheng@623
|
227 $doc->process('po_in_name' => \@pos,
|
dongsheng@623
|
228 'file_in_name' => \@masters,
|
dongsheng@623
|
229 'file_in_charset' => $mastchar,
|
dongsheng@623
|
230 'file_out_charset' => $locchar,
|
dongsheng@623
|
231 'addendum_charset' => $addchar);
|
dongsheng@623
|
232
|
dongsheng@623
|
233 my ($percent,$hit,$queries) = $doc->stats();
|
dongsheng@623
|
234 my $error=0;
|
dongsheng@623
|
235
|
dongsheng@623
|
236 print STDERR wrap_msg(gettext("%s is %s%% translated (%s of %s strings)."),
|
dongsheng@623
|
237 $master_filename, $percent, $hit, $queries)
|
dongsheng@623
|
238 if (scalar @verbose) && ($percent>=$threshold);
|
dongsheng@623
|
239
|
dongsheng@623
|
240
|
dongsheng@623
|
241 if ($percent<$threshold) {
|
dongsheng@623
|
242 print STDERR wrap_msg(gettext("Discard the translation of %s (only %s%% translated; need %s%%)."),
|
dongsheng@623
|
243 $master_filename, $percent, $threshold);
|
dongsheng@623
|
244 unlink($outfile) if (-e $outfile);
|
dongsheng@623
|
245 } else {
|
dongsheng@623
|
246 foreach my $add (@addfiles) {
|
dongsheng@623
|
247 unless ($doc->addendum($add)) {
|
dongsheng@623
|
248 unlink($outfile) if (-e $outfile);
|
dongsheng@623
|
249 die wrap_msg(gettext("Discard the translation of %s (addendum %s does not apply)."),
|
dongsheng@623
|
250 $master_filename, $add);
|
dongsheng@623
|
251 }
|
dongsheng@623
|
252 }
|
dongsheng@623
|
253 $doc->write($outfile);
|
dongsheng@623
|
254 }
|
dongsheng@623
|
255
|
dongsheng@623
|
256 1;
|
dongsheng@623
|
257
|