-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_pot_file.pl
executable file
·63 lines (54 loc) · 1.81 KB
/
update_pot_file.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env perl
use strict;
use warnings;
#
# update messages.pot file with new strings detected.
#
use Cwd qw{ cwd };
use File::Spec::Functions qw{ catfile catdir };
use File::Find::Rule;
use Getopt::Long;
GetOptions (
'verbose' => \(my $verbose = 0),
'cleanup!' => \(my $cleanup = 1),
'no-version-check' => \(my $no_version_check = 0),
) or die "Error while parsing command-line parameters.\n";
my $cwd = cwd;
my $localedir = catdir( $cwd, 'share', 'locale' );
unless ( -d $localedir ) {
# Search for the 'locale' directory when 'share/locale'
# directory is not found
# and discard CVS/.svn/.git and blib folders
my $rule = File::Find::Rule->new;
$rule->or(
$rule->new->directory->name( 'CVS', '.svn', '.git', 'blib' )->prune->discard,
$rule->new
);
my @files = $rule->name('locale')->in($cwd);
if ( scalar @files > 0 ) {
$localedir = $files[0];
} else {
die "locale directory not found.\n";
}
}
my $pot_file = catfile( $localedir, 'messages.pot' );
my $pmfiles = catfile( $cwd, 'pm-files.txt' );
# build list of perl modules from where to extract strings
my @pmfiles = grep {/^lib/} File::Find::Rule->file()->name('*.pm')->relative->in($cwd);
open my $fh, '>', $pmfiles or die "cannot open '$pmfiles': $!\n";
print $fh map {"$_$/"} @pmfiles;
close $fh;
unlink $pot_file;
my ($gettext) = grep { $_ =~ /^xgettext/ } qx{xgettext -V};
chomp $gettext;
if ( (not $no_version_check) && $gettext ne 'xgettext (GNU gettext-tools) 0.17' ) {
die "Due to bug #1132 we only allow the use of v0.17 of xgettext\n";
}
my @xgettext = ('xgettext', '--keyword=_T', '--from-code=utf-8', '-o', $pot_file, '-f', $pmfiles, '--sort-output');
print STDERR (join ' ', @xgettext) . "\n" if $verbose;
system( @xgettext ) == 0
or die 'xgettext exited with return code ' . ( $? >> 8 ) . "\n";
# cleanup
if ($cleanup) {
unlink $pmfiles;
}