source: subversion/applications/editors/josm/plugins/photoadjust/i18n/pomerge.pl @ 33803

Last change on this file since 33803 was 30155, checked in by holgermappt, 6 years ago

Reorganized i18n.

  • Property svn:executable set to *
File size: 2.5 KB
Line 
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
9pomerge.pl - Run msgmerge with the files in the po directory and
10    remove untranslated strings.
11
12=head1 SYNOPSIS
13
14B<poimport.pl> [B<--help>] [B<--man>] [B<--podir> I<po>]
15    [B<--project> I<project>]
16
17=head1 DESCRIPTION
18
19This script merges the translated strings with the template POT file
20(msgmerge).  It then removes all untranslated strings (msgattrib).
21The script works with all PO files in the po directory.
22
23=head1 OPTIONS
24
25=over 4
26
27=item B<--help>
28
29Prints a brief help message and exits.
30
31=item B<--man>
32
33Prints the manual page and exits.
34
35=item B<--podir>
36
37Directory with PO files that are to be merged.  Default is F<po>.
38
39=item B<--project>
40
41Project or plugin name.  If the name of the template is F<plugin.pot>,
42then this name is I<plugin>.  Default is I<josm>.
43
44=back
45
46=cut
47#####################################################################
48
49use strict;
50use File::Spec::Functions;
51use Getopt::Long;
52use Pod::Usage;
53
54my $podir = "po";               ### Directory with PO files that are merged.
55my $project = "josm";           ### Project/plugin name.
56my $showhelp = 0;               ### Show help screen.
57my $showman = 0;                ### Show manual page of this script.
58
59GetOptions('help|?|h'  => \$showhelp,
60           'man'       => \$showman,
61           'podir=s'   => \$podir,
62           'project=s' => \$project,
63          ) or pod2usage(2);
64
65pod2usage(1) if $showhelp;
66pod2usage(-exitstatus => 0, -verbose => 2) if $showman;
67
68### Path to POT file.
69my $potfile = catfile($podir, $project . ".pot");
70
71foreach 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}
Note: See TracBrowser for help on using the repository browser.