hgbook

annotate tools/po4a/po4a-updatepo @ 643:61ac4138e086

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