dongsheng@623: #! /usr/bin/env perl dongsheng@623: eval 'exec perl -S $0 ${1+"$@"}' dongsheng@623: if $running_under_some_shell; dongsheng@623: dongsheng@623: # pod-updatepo -- Update the po translation of POD data. dongsheng@623: # $Id: po4a-updatepo,v 1.44 2009-03-07 12:33:10 nekral-guest Exp $ dongsheng@623: # dongsheng@623: # Copyright 2002, 2003, 2004 by Martin Quinson (mquinson#debian.org) dongsheng@623: # dongsheng@623: # This program is free software; you can redistribute it and/or modify it dongsheng@623: # under the terms of GPL (see COPYING). dongsheng@623: dongsheng@623: =head1 NAME dongsheng@623: dongsheng@623: po4a-updatepo - update the translation (in po format) of documentation dongsheng@623: dongsheng@623: =head1 SYNOPSIS dongsheng@623: dongsheng@623: po4a-updatepo -f EfmtE (-m Emaster.docE)+ (-p EXX.poE)+ dongsheng@623: dongsheng@623: (XX.po are the outputs, all others are inputs) dongsheng@623: dongsheng@623: =head1 DESCRIPTION dongsheng@623: dongsheng@623: The po4a (po for anything) project goal is to ease translations (and more dongsheng@623: interestingly, the maintenance of translations) using gettext tools on dongsheng@623: areas where they were not expected like documentation. dongsheng@623: dongsheng@623: The C script is in charge of updating po files to make dongsheng@623: them reflect the changes made to the original documentation file. For that, dongsheng@623: it converts the documentation file to a pot file, and call L dongsheng@623: on this new pot and on the provided po files. dongsheng@623: dongsheng@623: It is possible to give more than one po file (if you want to update several dongsheng@623: languages at once), and several documentation files (if you want to store dongsheng@623: the translations of several documents in the same po file). dongsheng@623: dongsheng@623: If the master document has non-ascii characters, it will convert the po files dongsheng@623: to utf-8 (if they weren't already), in order to allow non-standard characters dongsheng@623: in a culture independent way. dongsheng@623: dongsheng@623: =head1 COMMAND-LINE OPTIONS dongsheng@623: dongsheng@623: =over 4 dongsheng@623: dongsheng@623: =item -f, --format dongsheng@623: dongsheng@623: Format of the documentation you want to handle. Use the --help-format dongsheng@623: option to see the list of available formats. dongsheng@623: dongsheng@623: =item -m, --master dongsheng@623: dongsheng@623: File(s) containing the master document to translate. dongsheng@623: dongsheng@623: =item -M, --master-charset dongsheng@623: dongsheng@623: Charset of the files containing the document to translate. Note that all dongsheng@623: files must have the same charset. dongsheng@623: dongsheng@623: =item -p, --po dongsheng@623: dongsheng@623: Po file(s) to update. If these files do not exist, they are created by dongsheng@623: C. dongsheng@623: dongsheng@623: =item -o, --option dongsheng@623: dongsheng@623: Extra option(s) to pass to the format plugin and other po4a internal module. dongsheng@623: Specify each option in the 'name=value' format. See the documentation of dongsheng@623: each plugin for more information about the valid options and their meanings. dongsheng@623: dongsheng@623: =item --previous dongsheng@623: dongsheng@623: This option adds '--previous' to the options passed to msgmerge. dongsheng@623: It requires gettext 0.16 or later. dongsheng@623: dongsheng@623: =item --msgmerge-opt options dongsheng@623: dongsheng@623: Extra options for msgmerge. dongsheng@623: dongsheng@623: =item -h, --help dongsheng@623: dongsheng@623: Show a short help message. dongsheng@623: dongsheng@623: =item --help-format dongsheng@623: dongsheng@623: List the documentation format handled by po4a. dongsheng@623: dongsheng@623: =item -V, --version dongsheng@623: dongsheng@623: Display the version of the script and exit. dongsheng@623: dongsheng@623: =item -v, --verbose dongsheng@623: dongsheng@623: Increase the verbosity of the program. dongsheng@623: dongsheng@623: =item -d, --debug dongsheng@623: dongsheng@623: Output some debugging information. dongsheng@623: dongsheng@623: =back dongsheng@623: dongsheng@623: =head1 SEE ALSO dongsheng@623: dongsheng@623: L, L, L, L. dongsheng@623: dongsheng@623: =head1 AUTHORS dongsheng@623: dongsheng@623: Denis Barbier dongsheng@623: Martin Quinson (mquinson#debian.org) dongsheng@623: dongsheng@623: =head1 COPYRIGHT AND LICENSE dongsheng@623: dongsheng@623: Copyright 2002, 2003, 2004, 2005 by SPI, inc. dongsheng@623: dongsheng@623: This program is free software; you may redistribute it and/or modify it dongsheng@623: under the terms of GPL (see the COPYING file). dongsheng@623: dongsheng@623: =cut dongsheng@623: dongsheng@623: use 5.006; dongsheng@623: use strict; dongsheng@623: use warnings; dongsheng@623: dongsheng@623: use Getopt::Long qw(GetOptions); dongsheng@623: use Locale::Po4a::Po; dongsheng@623: dongsheng@623: use Locale::Po4a::Chooser; dongsheng@623: use Locale::Po4a::TransTractor; dongsheng@623: use Locale::Po4a::Common; dongsheng@623: dongsheng@623: use Pod::Usage qw(pod2usage); dongsheng@623: dongsheng@623: use File::Temp; dongsheng@623: dongsheng@623: Locale::Po4a::Common::textdomain('po4a'); dongsheng@623: dongsheng@623: sub show_version { dongsheng@623: Locale::Po4a::Common::show_version("po4a-updatepo"); dongsheng@623: exit 0; dongsheng@623: } dongsheng@623: dongsheng@623: dongsheng@623: # init commandline parser dongsheng@623: Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev'); dongsheng@623: dongsheng@623: # Parse our options dongsheng@623: my (@masterfiles,@pofiles); dongsheng@623: my ($help,$help_fmt,$verbose,$debug,$format,@options); dongsheng@623: my $mastchar; dongsheng@623: my $previous; dongsheng@623: my $msgmerge_opt = ""; dongsheng@623: GetOptions('help|h' => \$help, dongsheng@623: 'help-format' => \$help_fmt, dongsheng@623: dongsheng@623: 'master|m=s' => \@masterfiles, dongsheng@623: 'po|p=s' => \@pofiles, dongsheng@623: 'format|f=s' => \$format, dongsheng@623: dongsheng@623: 'master-charset|M=s' => \$mastchar, dongsheng@623: dongsheng@623: 'option|o=s' => \@options, dongsheng@623: dongsheng@623: 'previous' => \$previous, dongsheng@623: 'msgmerge-opt=s' => \$msgmerge_opt, dongsheng@623: dongsheng@623: 'verbose|v' => \$verbose, dongsheng@623: 'debug|d' => \$debug, dongsheng@623: 'version|V' => \&show_version) dongsheng@623: or pod2usage(); dongsheng@623: dongsheng@623: $help && pod2usage (-verbose => 1, -exitval => 0); dongsheng@623: $help_fmt && Locale::Po4a::Chooser::list(0); dongsheng@623: pod2usage () if scalar @masterfiles < 1 || scalar @pofiles < 1; dongsheng@623: dongsheng@623: $msgmerge_opt .= " --previous" if $previous; dongsheng@623: dongsheng@623: my %options = ( dongsheng@623: "verbose" => $verbose, dongsheng@623: "debug" => $debug); dongsheng@623: dongsheng@623: foreach (@options) { dongsheng@623: if (m/^([^=]*)=(.*)$/) { dongsheng@623: $options{$1}="$2"; dongsheng@623: } else { dongsheng@623: $options{$_}=1; dongsheng@623: } dongsheng@623: } dongsheng@623: dongsheng@623: # parser dongsheng@623: my ($doc)=Locale::Po4a::Chooser::new($format,%options); dongsheng@623: dongsheng@623: map { -e $_ || die wrap_msg(gettext("File %s does not exist."), $_) } @masterfiles; dongsheng@623: map { die wrap_msg(gettext("po4a-updatepo can't take the input po from stdin.")) dongsheng@623: if $_ eq '-' && !-e '-'} @pofiles; dongsheng@623: dongsheng@623: my ($pot_filename); dongsheng@623: (undef,$pot_filename)=File::Temp->tempfile("po4a-updatepoXXXX", dongsheng@623: DIR => "/tmp", dongsheng@623: SUFFIX => ".pot", dongsheng@623: OPEN => 0, dongsheng@623: UNLINK => 0) dongsheng@623: or die wrap_msg(gettext("Can't create a temporary pot file: %s"), $!); dongsheng@623: dongsheng@623: dongsheng@623: print STDERR wrap_msg(gettext("Parse input files... ")) if $verbose; dongsheng@623: dongsheng@623: $doc->{TT}{utf_mode} = 1; dongsheng@623: dongsheng@623: $doc->process('file_in_name' => \@masterfiles, dongsheng@623: 'file_in_charset' => $mastchar, dongsheng@623: 'po_out_name' => $pot_filename, dongsheng@623: 'debug' => $debug, dongsheng@623: 'verbose' => $verbose); dongsheng@623: dongsheng@623: print STDERR wrap_msg(gettext("done.")) if $verbose; dongsheng@623: dongsheng@623: dongsheng@623: while (my $po_filename=shift @pofiles) { dongsheng@623: if (-e $po_filename) { dongsheng@623: print STDERR wrap_msg(gettext("Updating %s:"), $po_filename) dongsheng@623: if $verbose; dongsheng@623: my $cmd = "msgmerge $msgmerge_opt -U $po_filename $pot_filename"; dongsheng@623: system ($cmd) == 0 dongsheng@623: or die wrap_msg(gettext("Error while running msgmerge: %s"), $!); dongsheng@623: system "msgfmt --statistics -v -o /dev/null $po_filename" dongsheng@623: if $verbose; dongsheng@623: } else { dongsheng@623: print STDERR wrap_msg(gettext("Creating %s:"), $po_filename) dongsheng@623: if $verbose; dongsheng@623: system ("cp",$pot_filename,$po_filename) == 0 dongsheng@623: or die wrap_msg(gettext("Error while copying the po file: %s"), $!); dongsheng@623: } dongsheng@623: } dongsheng@623: dongsheng@623: unlink($pot_filename);