summaryrefslogtreecommitdiff
path: root/lib/Locale/Maketext/Extract
diff options
context:
space:
mode:
authorAndreas Brachold <vdr07@deltab.de>2007-08-13 18:41:27 +0000
committerAndreas Brachold <vdr07@deltab.de>2007-08-13 18:41:27 +0000
commitbcbf441e09fb502cf64924ff2530fa144bdf52c5 (patch)
treef377707a2dac078db8cd0c7d7abfe69ac1006d71 /lib/Locale/Maketext/Extract
downloadxxv-bcbf441e09fb502cf64924ff2530fa144bdf52c5.tar.gz
xxv-bcbf441e09fb502cf64924ff2530fa144bdf52c5.tar.bz2
* Move files to trunk
Diffstat (limited to 'lib/Locale/Maketext/Extract')
-rw-r--r--lib/Locale/Maketext/Extract/Run.pm83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/Locale/Maketext/Extract/Run.pm b/lib/Locale/Maketext/Extract/Run.pm
new file mode 100644
index 0000000..f3ddd62
--- /dev/null
+++ b/lib/Locale/Maketext/Extract/Run.pm
@@ -0,0 +1,83 @@
+package Locale::Maketext::Extract::Run;
+
+use strict;
+use vars qw( @ISA @EXPORT_OK );
+
+use Cwd;
+use File::Find;
+use Getopt::Long;
+use Locale::Maketext::Extract;
+use Exporter;
+
+@ISA = 'Exporter';
+@EXPORT_OK = 'xgettext';
+
+sub xgettext { __PACKAGE__->run(@_) }
+
+sub run {
+ my $self = shift;
+ local @ARGV = @_;
+
+ my %opts;
+ Getopt::Long::Configure("no_ignore_case");
+ Getopt::Long::GetOptions( \%opts,
+ 'f|files-from:s@',
+ 'D|directory:s@',
+ 'u|unescaped',
+ 'g|gnu-gettext',
+ 'o|output:s@',
+ 'd|default-domain:s',
+ 'p|output-dir:s@',
+ 'h|help',
+ ) or help();
+ help() if $opts{h};
+
+ my @po = @{$opts{o} || [($opts{d}||'messages').'.po']};
+
+ foreach my $file (@{$opts{f}||[]}) {
+ open FILE, $file or die "Cannot open $file: $!";
+ while (<FILE>) {
+ push @ARGV, $_ if -r and !-d;
+ }
+ }
+
+ foreach my $dir (@{$opts{D}||[]}) {
+ File::Find::find( {
+ wanted => sub {
+ return if
+ ( -d ) ||
+ ( $File::Find::dir =~ 'lib/blib|lib/t/autogen|var|m4|local' ) ||
+ ( /\.po$|\.bak$|~|,D|,B$/i ) ||
+ ( /^[\.#]/ );
+ push @ARGV, $File::Find::name;
+ },
+ follow => 1,
+ }, $dir );
+ }
+
+ @ARGV = ('-') unless @ARGV;
+ s!^.[/\\]!! for @ARGV;
+
+ my $cwd = getcwd();
+
+ foreach my $dir (@{$opts{p}||['.']}) {
+ foreach my $po (@po) {
+ my $Ext = Locale::Maketext::Extract->new;
+ $Ext->read_po($po, $opts{u}) if -r $po;
+ $Ext->extract_file($_) for grep !/\.po$/i, @ARGV;
+ $Ext->compile($opts{u}) or next;
+
+ chdir $dir;
+ $Ext->write_po($po, $opts{g});
+ chdir $cwd;
+ }
+ }
+}
+
+sub help {
+ local $SIG{__WARN__} = sub {};
+ { exec "perldoc $0"; }
+ { exec "pod2text $0"; }
+}
+
+1;