script-fu-xgettext 1.15 KB
Newer Older
Sven Neumann's avatar
Sven Neumann committed
1 2
#!/usr/bin/perl

3 4 5
# a lame attempt at xgettext for scheme
# adapted from pxgettext as found in the plug-ins/perl directory

6 7 8
# TODO:
# proper linenumbers

9
# There are rumors that perl version 5.005_02 has a bug
10
# resulting in an endless loop and a memory leak in the 
11 12 13 14 15 16
# regex machinery. 
#
# It seems to work however. I'll leave this check commented out until
# people report problems.
#
# die ("Your version of Perl (5.005_02) is broken!\nCan't extract the strings from the scripts.\nA lot of messages will be missing from your gimp-script-fu.pot file.\n\n") if $] eq 5.005_02;
17 18 19

undef $/;

20
my $file;
21 22 23 24 25 26 27 28 29
my $fileposition;
my $e;
my $s;

while (<>) {
    $file = $ARGV;
    $file =~ s/\.\.\///;

    while (/_\(?"((?:[^"\\]+|\\.)*)"\)?/sg) {
30 31 32 33 34 35 36 37 38 39 40 41 42 43
        my $s = $1;
        if ($s =~ /\n/) {
            $e = "msgid \"\"\n";
            for (split /\n/, $s) {
                $e .= "\"$_\\n\"\n";
            }
        } else {
            $e = "msgid \"$s\"\n";
        }
        $e .= "msgstr \"\"\n";

        $fileposition = "#: $file:0\n";

        push @{$entry{$e}}, $fileposition;
44
    }
Sven Neumann's avatar
Sven Neumann committed
45 46
}

47 48 49 50
foreach $e (sort keys %entry) {
    print @{$entry{$e}};
    print $e;
    print "\n";
Sven Neumann's avatar
Sven Neumann committed
51 52
}