mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-30 12:43:41 +01:00
1ec5de9534
ebuild.sh/buildme update
272 lines
7.8 KiB
Perl
Executable File
272 lines
7.8 KiB
Perl
Executable File
#! /usr/bin/env perl
|
|
eval 'exec perl -S $0 ${1+"$@"}'
|
|
if $running_under_some_shell;
|
|
|
|
# po4a-gettextize -- convert an original file to a PO file
|
|
#
|
|
# Copyright 2002-2012 by SPI, inc.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify it
|
|
# under the terms of GPL (see COPYING).
|
|
|
|
=encoding UTF-8
|
|
|
|
=head1 NAME
|
|
|
|
po4a-gettextize - convert an original file (and its translation) to a PO file
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
B<po4a-gettextize> B<-f> I<fmt> B<-m> I<master.doc> [B<-l> I<XX.doc>] B<-p> I<XX.po>
|
|
|
|
(I<XX.po> is the output, all others are inputs)
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
The po4a (PO for anything) project goal is to ease translations (and more
|
|
interestingly, the maintenance of translations) using gettext tools on
|
|
areas where they were not expected like documentation.
|
|
|
|
The B<po4a-gettextize> script is in charge of converting documentation
|
|
files to PO files. If you start a new translation, B<po4a-gettextize>
|
|
will extract the translatable strings from the documentation file and
|
|
write a POT file from it.
|
|
|
|
If you already have a translated file, B<po4a-gettextize> will try to
|
|
extract the translations it contains and put them in place in the written
|
|
PO file. Be warned that very few intelligence is used in this process: the
|
|
Nth string of the translated file is supposed to be the translation of the
|
|
Nth string in the original. If it's not the case, you're dead. That's why
|
|
it is very important that both files share exactly the same structure.
|
|
|
|
However, B<po4a-gettextize> will diagnose your death by detecting any
|
|
desynchronisation between files, and reporting where they occur. In that
|
|
case, you should edit manually the files to solve the reported
|
|
disparity. Even if no error were reported, you should check carefully that the
|
|
generated PO file is correct (i.e. that each msgstr is the translation of
|
|
the associated msgid, and not the one before or after).
|
|
|
|
Even if the script manages to do its job without any apparent problem, it still
|
|
marks all extracted translations as fuzzy, to make sure that the translator
|
|
will have a look at them, and detect any remaining problem.
|
|
|
|
If the master document has non-ASCII characters, the new generated PO file
|
|
will be in UTF-8, in order to allow non-standard characters in a culture
|
|
independent way. Else (if the master document is completely in ASCII), the
|
|
generated PO will use the encoding of the translated input document.
|
|
|
|
=head1 OPTIONS
|
|
|
|
=over 4
|
|
|
|
=item B<-f>, B<--format>
|
|
|
|
Format of the documentation you want to handle. Use the B<--help-format>
|
|
option to see the list of available formats.
|
|
|
|
=item B<-m>, B<--master>
|
|
|
|
File containing the master document to translate. You can use this option
|
|
multiple times if you want to gettextize multiple documents.
|
|
|
|
=item B<-M>, B<--master-charset>
|
|
|
|
Charset of the file containing the document to translate.
|
|
|
|
=item B<-l>, B<--localized>
|
|
|
|
File containing the localized (translated) document. If you provided
|
|
multiple master files, you may wish to provide multiple localized file by
|
|
using this option more than once.
|
|
|
|
=item B<-L>, B<--localized-charset>
|
|
|
|
Charset of the file containing the localized document.
|
|
|
|
=item B<-p>, B<--po>
|
|
|
|
File where the message catalog should be written. If not given, the message
|
|
catalog will be written to the standard output.
|
|
|
|
=item B<-o>, B<--option>
|
|
|
|
Extra option(s) to pass to the format plugin. Specify each option in the
|
|
'I<name>B<=>I<value>' format. See the documentation of each plugin for more
|
|
information about the valid options and their meanings.
|
|
|
|
=item B<-h>, B<--help>
|
|
|
|
Show a short help message.
|
|
|
|
=item B<--help-format>
|
|
|
|
List the documentation formats understood by po4a.
|
|
|
|
=item B<-V>, B<--version>
|
|
|
|
Display the version of the script and exit.
|
|
|
|
=item B<-v>, B<--verbose>
|
|
|
|
Increase the verbosity of the program.
|
|
|
|
=item B<-d>, B<--debug>
|
|
|
|
Output some debugging information.
|
|
|
|
=item B<--msgid-bugs-address> I<email@address>
|
|
|
|
Set the report address for msgid bugs. By default, the created POT files
|
|
have no Report-Msgid-Bugs-To fields.
|
|
|
|
=item B<--copyright-holder> I<string>
|
|
|
|
Set the copyright holder in the POT header. The default value is
|
|
"Free Software Foundation, Inc."
|
|
|
|
=item B<--package-name> I<string>
|
|
|
|
Set the package name for the POT header. The default is "PACKAGE".
|
|
|
|
=item B<--package-version> I<string>
|
|
|
|
Set the package version for the POT header. The default is "VERSION".
|
|
|
|
=back
|
|
|
|
=head1 SEE ALSO
|
|
|
|
L<po4a-normalize(1)>,
|
|
L<po4a-translate(1)>,
|
|
L<po4a-updatepo(1)>,
|
|
L<po4a(7)>
|
|
|
|
=head1 AUTHORS
|
|
|
|
Denis Barbier <barbier@linuxfr.org>
|
|
Nicolas François <nicolas.francois@centraliens.net>
|
|
Martin Quinson (mquinson#debian.org)
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
Copyright 2002-2012 by SPI, inc.
|
|
|
|
This program is free software; you may redistribute it and/or modify it
|
|
under the terms of GPL (see the COPYING file).
|
|
|
|
=cut
|
|
|
|
use 5.006;
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Getopt::Long qw(GetOptions);
|
|
|
|
use Locale::Po4a::Chooser;
|
|
use Locale::Po4a::TransTractor;
|
|
use Locale::Po4a::Common;
|
|
|
|
use Pod::Usage qw(pod2usage);
|
|
|
|
Locale::Po4a::Common::textdomain('po4a');
|
|
|
|
|
|
sub show_version {
|
|
Locale::Po4a::Common::show_version("po4a-gettextize");
|
|
exit 0;
|
|
}
|
|
|
|
my %opts = (
|
|
"verbose" => 0,
|
|
"debug" => 0,
|
|
"copyright-holder" => undef,
|
|
"msgid-bugs-address" => undef,
|
|
"package-name" => undef,
|
|
"package-version" => undef);
|
|
|
|
my ($pofile)=('-');
|
|
my (@masterfile,@locfile,$help_fmt,$help,$type,@options);
|
|
my ($mastchar,$locchar);
|
|
Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
|
|
GetOptions(
|
|
'help|h' => \$help,
|
|
'help-format' => \$help_fmt,
|
|
|
|
'master|m=s' => \@masterfile,
|
|
'localized|l=s' => \@locfile,
|
|
'po|p=s' => \$pofile,
|
|
'format|f=s' => \$type,
|
|
|
|
'master-charset|M=s' => \$mastchar,
|
|
'localized-charset|L=s' => \$locchar,
|
|
|
|
'option|o=s' => \@options,
|
|
|
|
'copyright-holder=s' => \$opts{"copyright-holder"},
|
|
'msgid-bugs-address=s' => \$opts{"msgid-bugs-address"},
|
|
'package-name=s' => \$opts{"package-name"},
|
|
'package-version=s' => \$opts{"package-version"},
|
|
|
|
'verbose|v' => \$opts{"verbose"},
|
|
'debug|d' => \$opts{"debug"},
|
|
'version|V' => \&show_version
|
|
) or pod2usage();
|
|
|
|
# Argument check
|
|
$help && pod2usage (-verbose => 1, -exitval => 0);
|
|
$help_fmt && Locale::Po4a::Chooser::list(0);
|
|
pod2usage () if (scalar @ARGV > 1) || (scalar @masterfile < 1);
|
|
|
|
foreach (@options) {
|
|
if (m/^([^=]*)=(.*)$/) {
|
|
$opts{$1}="$2";
|
|
} else {
|
|
$opts{$_}=1;
|
|
}
|
|
}
|
|
# Check file existence
|
|
foreach my $file (@masterfile, @locfile) {
|
|
$file eq '-' || -e $file || die wrap_msg(gettext("File %s does not exist."), $file);
|
|
}
|
|
|
|
# Declare the TransTractor parsers
|
|
my ($mastertt,$transtt)=(Locale::Po4a::Chooser::new($type,%opts),
|
|
Locale::Po4a::Chooser::new($type,%opts));
|
|
|
|
# Parse master file forcing conversion to utf if it's not in ascii
|
|
foreach my $file (@masterfile) {
|
|
$mastertt->read($file);
|
|
}
|
|
$mastertt->{TT}{utf_mode} = 1;
|
|
if ($mastertt->{TT}{ascii_input}) {
|
|
$mastertt->detected_charset('ascii');
|
|
} elsif (defined($mastchar)) {
|
|
$mastertt->detected_charset($mastchar);
|
|
$mastertt->{TT}{po_in}->set_charset($mastchar);
|
|
}
|
|
$mastertt->parse;
|
|
|
|
|
|
unless (scalar @locfile >= 1) {
|
|
# Ok, outputing the pot extracted from original is enough
|
|
$mastertt->writepo($pofile);
|
|
} else {
|
|
# We have to merge two transtractor files
|
|
|
|
foreach my $file (@locfile) {
|
|
$transtt->read($file);
|
|
}
|
|
# We force the conversion to utf if the master document wasn't in ascii
|
|
$transtt->{TT}{utf_mode} = !$mastertt->{TT}{ascii_input};
|
|
$transtt->detected_charset($locchar);
|
|
$transtt->{TT}{po_in}->set_charset($locchar);
|
|
$transtt->parse;
|
|
|
|
my $mergedpo = Locale::Po4a::Po->gettextize($mastertt->getpoout(),
|
|
$transtt->getpoout());
|
|
|
|
$mergedpo->write($pofile);
|
|
}
|
|
|
|
__END__
|