hgbook
diff tools/po4a/po4a-updatepo @ 624:3c5e1c03cc3e
Add XSL stylesheets for DocBook
author | Dongsheng Song <dongsheng.song@gmail.com> |
---|---|
date | Thu Mar 12 15:47:15 2009 +0800 (2009-03-12) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/po4a/po4a-updatepo Thu Mar 12 15:47:15 2009 +0800 1.3 @@ -0,0 +1,235 @@ 1.4 +#! /usr/bin/env perl 1.5 +eval 'exec perl -S $0 ${1+"$@"}' 1.6 + if $running_under_some_shell; 1.7 + 1.8 +# pod-updatepo -- Update the po translation of POD data. 1.9 +# $Id: po4a-updatepo,v 1.44 2009-03-07 12:33:10 nekral-guest Exp $ 1.10 +# 1.11 +# Copyright 2002, 2003, 2004 by Martin Quinson (mquinson#debian.org) 1.12 +# 1.13 +# This program is free software; you can redistribute it and/or modify it 1.14 +# under the terms of GPL (see COPYING). 1.15 + 1.16 +=head1 NAME 1.17 + 1.18 +po4a-updatepo - update the translation (in po format) of documentation 1.19 + 1.20 +=head1 SYNOPSIS 1.21 + 1.22 +po4a-updatepo -f E<lt>fmtE<gt> (-m E<lt>master.docE<gt>)+ (-p E<lt>XX.poE<gt>)+ 1.23 + 1.24 +(XX.po are the outputs, all others are inputs) 1.25 + 1.26 +=head1 DESCRIPTION 1.27 + 1.28 +The po4a (po for anything) project goal is to ease translations (and more 1.29 +interestingly, the maintenance of translations) using gettext tools on 1.30 +areas where they were not expected like documentation. 1.31 + 1.32 +The C<po4a-updatepo> script is in charge of updating po files to make 1.33 +them reflect the changes made to the original documentation file. For that, 1.34 +it converts the documentation file to a pot file, and call L<msgmerge(1)> 1.35 +on this new pot and on the provided po files. 1.36 + 1.37 +It is possible to give more than one po file (if you want to update several 1.38 +languages at once), and several documentation files (if you want to store 1.39 +the translations of several documents in the same po file). 1.40 + 1.41 +If the master document has non-ascii characters, it will convert the po files 1.42 +to utf-8 (if they weren't already), in order to allow non-standard characters 1.43 +in a culture independent way. 1.44 + 1.45 +=head1 COMMAND-LINE OPTIONS 1.46 + 1.47 +=over 4 1.48 + 1.49 +=item -f, --format 1.50 + 1.51 +Format of the documentation you want to handle. Use the --help-format 1.52 +option to see the list of available formats. 1.53 + 1.54 +=item -m, --master 1.55 + 1.56 +File(s) containing the master document to translate. 1.57 + 1.58 +=item -M, --master-charset 1.59 + 1.60 +Charset of the files containing the document to translate. Note that all 1.61 +files must have the same charset. 1.62 + 1.63 +=item -p, --po 1.64 + 1.65 +Po file(s) to update. If these files do not exist, they are created by 1.66 +C<po4a-updatepo>. 1.67 + 1.68 +=item -o, --option 1.69 + 1.70 +Extra option(s) to pass to the format plugin and other po4a internal module. 1.71 +Specify each option in the 'name=value' format. See the documentation of 1.72 +each plugin for more information about the valid options and their meanings. 1.73 + 1.74 +=item --previous 1.75 + 1.76 +This option adds '--previous' to the options passed to msgmerge. 1.77 +It requires gettext 0.16 or later. 1.78 + 1.79 +=item --msgmerge-opt options 1.80 + 1.81 +Extra options for msgmerge. 1.82 + 1.83 +=item -h, --help 1.84 + 1.85 +Show a short help message. 1.86 + 1.87 +=item --help-format 1.88 + 1.89 +List the documentation format handled by po4a. 1.90 + 1.91 +=item -V, --version 1.92 + 1.93 +Display the version of the script and exit. 1.94 + 1.95 +=item -v, --verbose 1.96 + 1.97 +Increase the verbosity of the program. 1.98 + 1.99 +=item -d, --debug 1.100 + 1.101 +Output some debugging information. 1.102 + 1.103 +=back 1.104 + 1.105 +=head1 SEE ALSO 1.106 + 1.107 +L<po4a(7)>, L<po4a-gettextize(1)>, L<po4a-translate(1)>, L<po4a-normalize(1)>. 1.108 + 1.109 +=head1 AUTHORS 1.110 + 1.111 + Denis Barbier <barbier@linuxfr.org> 1.112 + Martin Quinson (mquinson#debian.org) 1.113 + 1.114 +=head1 COPYRIGHT AND LICENSE 1.115 + 1.116 +Copyright 2002, 2003, 2004, 2005 by SPI, inc. 1.117 + 1.118 +This program is free software; you may redistribute it and/or modify it 1.119 +under the terms of GPL (see the COPYING file). 1.120 + 1.121 +=cut 1.122 + 1.123 +use 5.006; 1.124 +use strict; 1.125 +use warnings; 1.126 + 1.127 +use Getopt::Long qw(GetOptions); 1.128 +use Locale::Po4a::Po; 1.129 + 1.130 +use Locale::Po4a::Chooser; 1.131 +use Locale::Po4a::TransTractor; 1.132 +use Locale::Po4a::Common; 1.133 + 1.134 +use Pod::Usage qw(pod2usage); 1.135 + 1.136 +use File::Temp; 1.137 + 1.138 +Locale::Po4a::Common::textdomain('po4a'); 1.139 + 1.140 +sub show_version { 1.141 + Locale::Po4a::Common::show_version("po4a-updatepo"); 1.142 + exit 0; 1.143 +} 1.144 + 1.145 + 1.146 +# init commandline parser 1.147 +Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev'); 1.148 + 1.149 +# Parse our options 1.150 +my (@masterfiles,@pofiles); 1.151 +my ($help,$help_fmt,$verbose,$debug,$format,@options); 1.152 +my $mastchar; 1.153 +my $previous; 1.154 +my $msgmerge_opt = ""; 1.155 +GetOptions('help|h' => \$help, 1.156 + 'help-format' => \$help_fmt, 1.157 + 1.158 + 'master|m=s' => \@masterfiles, 1.159 + 'po|p=s' => \@pofiles, 1.160 + 'format|f=s' => \$format, 1.161 + 1.162 + 'master-charset|M=s' => \$mastchar, 1.163 + 1.164 + 'option|o=s' => \@options, 1.165 + 1.166 + 'previous' => \$previous, 1.167 + 'msgmerge-opt=s' => \$msgmerge_opt, 1.168 + 1.169 + 'verbose|v' => \$verbose, 1.170 + 'debug|d' => \$debug, 1.171 + 'version|V' => \&show_version) 1.172 + or pod2usage(); 1.173 + 1.174 +$help && pod2usage (-verbose => 1, -exitval => 0); 1.175 +$help_fmt && Locale::Po4a::Chooser::list(0); 1.176 +pod2usage () if scalar @masterfiles < 1 || scalar @pofiles < 1; 1.177 + 1.178 +$msgmerge_opt .= " --previous" if $previous; 1.179 + 1.180 +my %options = ( 1.181 + "verbose" => $verbose, 1.182 + "debug" => $debug); 1.183 + 1.184 +foreach (@options) { 1.185 + if (m/^([^=]*)=(.*)$/) { 1.186 + $options{$1}="$2"; 1.187 + } else { 1.188 + $options{$_}=1; 1.189 + } 1.190 +} 1.191 + 1.192 +# parser 1.193 +my ($doc)=Locale::Po4a::Chooser::new($format,%options); 1.194 + 1.195 +map { -e $_ || die wrap_msg(gettext("File %s does not exist."), $_) } @masterfiles; 1.196 +map { die wrap_msg(gettext("po4a-updatepo can't take the input po from stdin.")) 1.197 + if $_ eq '-' && !-e '-'} @pofiles; 1.198 + 1.199 +my ($pot_filename); 1.200 +(undef,$pot_filename)=File::Temp->tempfile("po4a-updatepoXXXX", 1.201 + DIR => "/tmp", 1.202 + SUFFIX => ".pot", 1.203 + OPEN => 0, 1.204 + UNLINK => 0) 1.205 + or die wrap_msg(gettext("Can't create a temporary pot file: %s"), $!); 1.206 + 1.207 + 1.208 +print STDERR wrap_msg(gettext("Parse input files... ")) if $verbose; 1.209 + 1.210 +$doc->{TT}{utf_mode} = 1; 1.211 + 1.212 +$doc->process('file_in_name' => \@masterfiles, 1.213 + 'file_in_charset' => $mastchar, 1.214 + 'po_out_name' => $pot_filename, 1.215 + 'debug' => $debug, 1.216 + 'verbose' => $verbose); 1.217 + 1.218 +print STDERR wrap_msg(gettext("done.")) if $verbose; 1.219 + 1.220 + 1.221 +while (my $po_filename=shift @pofiles) { 1.222 + if (-e $po_filename) { 1.223 + print STDERR wrap_msg(gettext("Updating %s:"), $po_filename) 1.224 + if $verbose; 1.225 + my $cmd = "msgmerge $msgmerge_opt -U $po_filename $pot_filename"; 1.226 + system ($cmd) == 0 1.227 + or die wrap_msg(gettext("Error while running msgmerge: %s"), $!); 1.228 + system "msgfmt --statistics -v -o /dev/null $po_filename" 1.229 + if $verbose; 1.230 + } else { 1.231 + print STDERR wrap_msg(gettext("Creating %s:"), $po_filename) 1.232 + if $verbose; 1.233 + system ("cp",$pot_filename,$po_filename) == 0 1.234 + or die wrap_msg(gettext("Error while copying the po file: %s"), $!); 1.235 + } 1.236 +} 1.237 + 1.238 +unlink($pot_filename);