[30155] | 1 | #! /usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | #####################################################################
|
---|
| 4 | ### http://www.perl.com/doc/manual/html/utils/pod2man.html
|
---|
| 5 | ### http://search.cpan.org/dist/perl/pod/perlpod.pod
|
---|
| 6 |
|
---|
| 7 | =head1 NAME
|
---|
| 8 |
|
---|
| 9 | mftrans.pl - Add the translations of the plugin description to
|
---|
| 10 | the manifest.
|
---|
| 11 |
|
---|
| 12 | =head1 SYNOPSIS
|
---|
| 13 |
|
---|
| 14 | B<poimport.pl> [B<--help>] [B<--man>] [B<--manifest> I<MANIFEST>]
|
---|
| 15 | B<--description> I<"Plugin description."> I<po/*.po> ...
|
---|
| 16 |
|
---|
| 17 | =head1 DESCRIPTION
|
---|
| 18 |
|
---|
| 19 | Read the translations of the plugin description from the specified PO
|
---|
| 20 | files and add them to the manifest. Option B<--description> is
|
---|
| 21 | mandatory. PO files are expected as arguments.
|
---|
| 22 |
|
---|
| 23 | =head1 OPTIONS
|
---|
| 24 |
|
---|
| 25 | =over 4
|
---|
| 26 |
|
---|
| 27 | =item B<--help>
|
---|
| 28 |
|
---|
| 29 | Prints a brief help message and exits.
|
---|
| 30 |
|
---|
| 31 | =item B<--man>
|
---|
| 32 |
|
---|
| 33 | Prints the manual page and exits.
|
---|
| 34 |
|
---|
| 35 | =item B<--manifest>
|
---|
| 36 |
|
---|
| 37 | Manifest file the translations are added to. Default is F<MANIFEST>.
|
---|
| 38 |
|
---|
| 39 | =item B<--description>
|
---|
| 40 |
|
---|
| 41 | Plugin description. The same string that is specified as
|
---|
| 42 | C<plugin.description> in file F<build.xml>.
|
---|
| 43 |
|
---|
| 44 | =back
|
---|
| 45 |
|
---|
| 46 | =cut
|
---|
| 47 | #####################################################################
|
---|
| 48 |
|
---|
[30180] | 49 | use strict;
|
---|
[30155] | 50 | use utf8;
|
---|
| 51 | use Encode;
|
---|
| 52 | use Getopt::Long;
|
---|
| 53 | use Pod::Usage;
|
---|
[30180] | 54 | use File::Basename;
|
---|
| 55 | push(@INC, dirname($0));
|
---|
| 56 | require i18nlib;
|
---|
[30155] | 57 |
|
---|
| 58 | main();
|
---|
| 59 |
|
---|
| 60 | ### Add translations of plugin description to manifest. We write an
|
---|
| 61 | ### ant build file and call ant to do that. This way ant will take
|
---|
| 62 | ### care of the manifest format details.
|
---|
| 63 | sub addmfdescs($@)
|
---|
| 64 | {
|
---|
| 65 | my ($manifest, $descs, @langs) = @_;
|
---|
| 66 | my $buildfile = "build-descs.xml";
|
---|
| 67 | open FILE,">",$buildfile or die "Could not open file $buildfile: $!";
|
---|
| 68 | binmode FILE, ":encoding(utf8)";
|
---|
| 69 | print FILE <<EOT;
|
---|
| 70 | <?xml version="1.0" encoding="utf-8"?>
|
---|
| 71 | <project name="photoadjust" default="descs" basedir=".">
|
---|
| 72 | <target name="descs">
|
---|
| 73 | <manifest file="$manifest" mode="update">
|
---|
| 74 | EOT
|
---|
| 75 | foreach my $la (@langs) {
|
---|
| 76 | if (exists(${$descs}{$la})) {
|
---|
| 77 | my $trans = ${$descs}{$la};
|
---|
| 78 | print FILE " <attribute name=\"", $la,
|
---|
| 79 | "_Plugin-Description\" value=\"", $trans, "\"/>\n";
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | print FILE <<EOT;
|
---|
| 83 | </manifest>
|
---|
| 84 | </target>
|
---|
| 85 | </project>
|
---|
| 86 | EOT
|
---|
| 87 | close FILE;
|
---|
| 88 | system "ant -buildfile $buildfile";
|
---|
| 89 | unlink $buildfile;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | sub main
|
---|
| 93 | {
|
---|
| 94 | my $manifest = "MANIFEST"; ### Manifest file.
|
---|
| 95 | my $description = "No description."; ### Plugin description.
|
---|
| 96 | my $showhelp = 0; ### Show help screen.
|
---|
| 97 | my $showman = 0; ### Show manual page of this script.
|
---|
| 98 |
|
---|
| 99 | GetOptions('help|?|h' => \$showhelp,
|
---|
| 100 | 'man' => \$showman,
|
---|
| 101 | 'manifest=s' => \$manifest,
|
---|
| 102 | 'description=s' => \$description,
|
---|
| 103 | ) or pod2usage(2);
|
---|
| 104 |
|
---|
| 105 | pod2usage(1) if $showhelp;
|
---|
| 106 | pod2usage(-exitstatus => 0, -verbose => 2) if $showman;
|
---|
| 107 |
|
---|
| 108 | my %lang;
|
---|
| 109 | my @po;
|
---|
| 110 | foreach my $arg (@ARGV)
|
---|
| 111 | {
|
---|
| 112 | foreach my $f (glob $arg)
|
---|
| 113 | {
|
---|
| 114 | if($f =~ /\*/) { printf "Skipping $f\n"; }
|
---|
| 115 | elsif($f =~ /\.po$/) { push(@po, $f); }
|
---|
| 116 | else { die "unknown file extension."; }
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
[30180] | 119 | exit if ($#po < 0);
|
---|
[30155] | 120 | my %data = loadfiles(\%lang,@po);
|
---|
| 121 | my $descs = $data{$description};
|
---|
| 122 | my @langs = sort keys %lang;
|
---|
| 123 | addmfdescs($manifest, $descs, @langs);
|
---|
| 124 | }
|
---|