[30137] | 1 | #! /usr/bin/perl -w
|
---|
| 2 |
|
---|
[30155] | 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 | pomerge.pl - Run msgmerge with the files in the po directory and
|
---|
| 10 | remove untranslated strings.
|
---|
| 11 |
|
---|
| 12 | =head1 SYNOPSIS
|
---|
| 13 |
|
---|
| 14 | B<poimport.pl> [B<--help>] [B<--man>] [B<--podir> I<po>]
|
---|
| 15 | [B<--project> I<project>]
|
---|
| 16 |
|
---|
| 17 | =head1 DESCRIPTION
|
---|
| 18 |
|
---|
| 19 | This script merges the translated strings with the template POT file
|
---|
| 20 | (msgmerge). It then removes all untranslated strings (msgattrib).
|
---|
| 21 | The script works with all PO files in the po directory.
|
---|
| 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<--podir>
|
---|
| 36 |
|
---|
| 37 | Directory with PO files that are to be merged. Default is F<po>.
|
---|
| 38 |
|
---|
| 39 | =item B<--project>
|
---|
| 40 |
|
---|
| 41 | Project or plugin name. If the name of the template is F<plugin.pot>,
|
---|
| 42 | then this name is I<plugin>. Default is I<josm>.
|
---|
| 43 |
|
---|
| 44 | =back
|
---|
| 45 |
|
---|
| 46 | =cut
|
---|
| 47 | #####################################################################
|
---|
| 48 |
|
---|
[30137] | 49 | use strict;
|
---|
| 50 | use File::Spec::Functions;
|
---|
[30155] | 51 | use Getopt::Long;
|
---|
| 52 | use Pod::Usage;
|
---|
[30137] | 53 |
|
---|
[30155] | 54 | my $podir = "po"; ### Directory with PO files that are merged.
|
---|
| 55 | my $project = "josm"; ### Project/plugin name.
|
---|
| 56 | my $showhelp = 0; ### Show help screen.
|
---|
| 57 | my $showman = 0; ### Show manual page of this script.
|
---|
| 58 |
|
---|
| 59 | GetOptions('help|?|h' => \$showhelp,
|
---|
| 60 | 'man' => \$showman,
|
---|
| 61 | 'podir=s' => \$podir,
|
---|
| 62 | 'project=s' => \$project,
|
---|
| 63 | ) or pod2usage(2);
|
---|
| 64 |
|
---|
| 65 | pod2usage(1) if $showhelp;
|
---|
| 66 | pod2usage(-exitstatus => 0, -verbose => 2) if $showman;
|
---|
| 67 |
|
---|
[30137] | 68 | ### Path to POT file.
|
---|
[30155] | 69 | my $potfile = catfile($podir, $project . ".pot");
|
---|
[30137] | 70 |
|
---|
| 71 | foreach my $pofile (split("\n", `find $podir -name "*.po"`)) {
|
---|
| 72 | ### Merge translation with template.
|
---|
| 73 | my $cmd = "msgmerge --quiet --update --backup=none $pofile $potfile";
|
---|
| 74 | system $cmd;
|
---|
| 75 |
|
---|
| 76 | ### Get rid of all unneeded translations. Fuzzy translations are
|
---|
| 77 | ### removed too. msgattrib will not write an output file if nothing
|
---|
| 78 | ### is left. We move the original file and delete it afterwards to
|
---|
| 79 | ### preserve only languages with translations.
|
---|
| 80 | my $potmp = $pofile . ".tmp";
|
---|
| 81 | rename $pofile, $potmp;
|
---|
| 82 | $cmd = "msgattrib --output-file=$pofile --translated --no-fuzzy --no-obsolete $potmp";
|
---|
| 83 | system $cmd;
|
---|
| 84 | unlink $potmp;
|
---|
| 85 | if (-z $pofile) {
|
---|
| 86 | ### The PO file might be empty if there are no translated strings.
|
---|
| 87 | unlink $pofile;
|
---|
| 88 | }
|
---|
| 89 | if (-e $pofile . "~") {
|
---|
| 90 | ### Remove the backup copy.
|
---|
| 91 | unlink $pofile . "~";
|
---|
| 92 | }
|
---|
| 93 | }
|
---|