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 File::Spec;
my $code;
BEGIN {
my @spec = File::Spec->splitpath(__FILE__);
$spec[2] = 'PythonXGettext.py';
my $filename = File::Spec->catpath(@spec);
open HANDLE, "<$filename"
or die "Cannot open '$filename': $!\n";
$code = join '', <HANDLE>;
}
use Inline Python => 'DATA';
foreach my $key (keys %PythonXGettext::) {
no strict 'refs';
if ('new' ne $key && defined &{"PythonXGettext::$key"}) {
*{"Locale::XGettext::Python::$key"} = sub {
my ($self, @args) = @_;
$self->{__helper}->$key(@args);
};
}
}
Locale::XGettext::Python->newFromArgv(\@ARGV)->run->output;
package Locale::XGettext::Python;
use strict;
use base qw(Locale::XGettext);
sub newFromArgv {
my ($class, @args) = @_;
my $self = bless {}, $class;
$self->{__helper} = PythonXGettext->new($self);
$self->SUPER::newFromArgv(@args);
return $self;
}
__END__
__Python__
class PythonXGettext:
def __init__(self, xgettext):
self.xgettext = xgettext
def readFile(self, filename):
with open(filename) as f:
for line in f:
# You don't have to check that the line is empty. The
# PO header gets added after input has been processed.
self.xgettext.addEntry({'msgid': line});
# For extended usage, see the file PythonXGettext.py!
|