1#! /usr/bin/env perl
2
3use strict;
4
5Locale::XGettext::MyExtractor->newFromArgv(\@ARGV)->run->output;
6
7package Locale::XGettext::MyExtractor;
8
9use strict;
10
11use base qw(Locale::XGettext);
12
13our $VERSION = '23.4.89';
14
15sub readFile {
16    my ($self, $filename) = @_;
17
18    open my $fh, "<$filename" or die "Error reading '$filename': $!\n";
19
20    my $lineno = 0;
21    while (my $line = <$fh>) {
22        ++$lineno;
23        $self->addEntry({msgid => $line,
24                         reference => "$filename:$lineno"});
25    }
26
27    return $self;
28}
29
30sub extractFromNonFiles {
31    my ($self) = @_;
32
33    if (!$self->option("test_binding")) {
34        return $self;
35    }
36
37    print "Keywords:\n";
38
39    my $keywords = $self->keywords;
40    while (my ($keyword, $definition) = each %$keywords) {
41        print "function: $keyword\n";
42
43        my $context = $definition->context;
44        if (defined $context) {
45            print "  message context: argument #$context\n";
46        } else {
47            print "  message context: [none]\n";
48        }
49
50        my $singular = $definition->{singular};
51
52        print "  singular form: argument #$singular\n";
53
54        my $plural = $definition->plural;
55        if ($plural) {
56            print "  plural form: argument #$plural\n";
57        } else {
58            print "  plural form: [none]\n";
59        }
60
61        # Try --keyword=hello:1c,2,3,'"Hello, world!"' to see an
62        # automatic comment.
63        my $comment = $definition->comment;
64        $comment = '[none]' if !defined $comment;
65        print "  automatic comment: $comment\n";
66    }
67
68    return $self;
69}
70
71# Describe the type of input files.
72sub fileInformation {
73    return "Input files are plain text files and are converted into one PO entry\nfor every non-empty line."
74}
75
76# Return an array with the default keywords.  This is only used if the
77# method canKeywords() (see below) returns a truth value.  For the lines
78# extractor you would rather return undef or an empty hash.
79sub defaultKeywords {
80    return [
81        'gettext:1',
82        'ngettext:1, 2',
83        'pgettext:1c,2',
84        'npgettext:1c,2,3'
85    ];
86}
87
88# You can add more language specific options here.  It is your
89# responsibility that the option names do not conflict with those of the
90# wrapper.
91sub languageSpecificOptions {
92    return [
93                [
94                    # The option specification for Getopt::Long.  If you would
95                    # expect a string argument, you would have to specify
96                    # "test-binding=s" here, see
97                    # http://search.cpan.org/~jv/Getopt-Long/lib/Getopt/Long.pm
98                    # for details!
99                    'test-binding',
100
101                    #  The "name" of the option variable.  This is the argument
102                    # to option().
103                    'test_binding',
104
105                    # The option as displayed in the usage description.  The
106                    # leading four spaces compensate for the missing short
107                    # option.
108                    '    --test-binding',
109
110                    # The explanation of the option in the usage description.
111                    'print additional information for testing the language binding'
112                ]
113    ];
114}
115
116sub canExtractAll {
117    return;
118}
119
120sub canKeywords {
121    return 1;
122}
123
124sub canFlags {
125    return 1;
126}
127
1281;
129