Locale-Maketext-Lexicon

 view release on metacpan or  search on metacpan

lib/Locale/Maketext/Extract/Plugin/TextTemplate.pm  view on Meta::CPAN

package Locale::Maketext::Extract::Plugin::TextTemplate;
$Locale::Maketext::Extract::Plugin::TextTemplate::VERSION = '1.00';
use strict;
use base qw(Locale::Maketext::Extract::Plugin::Base);

# ABSTRACT: Text::Template format parser


sub file_types {
    return qw( * );
}

sub extract {
    my $self = shift;
    local $_ = shift;

    my $line = 1;
    pos($_) = 0;

    # Text::Template
    if ( $_ =~ /^STARTTEXT$/m and $_ =~ /^ENDTEXT$/m ) {
        require HTML::Parser;
        require Lingua::EN::Sentence;

        {

            package Locale::Maketext::Extract::Plugin::TextTemplate::Parser;
$Locale::Maketext::Extract::Plugin::TextTemplate::Parser::VERSION = '1.00';
our @ISA = 'HTML::Parser';
            *{'text'} = sub {
                my ( $self, $str, $is_cdata ) = @_;
                my $sentences = Lingua::EN::Sentence::get_sentences($str)
                    or return;
                $str =~ s/\n/ /g;
                $str =~ s/^\s+//;
                $str =~ s/\s+$//;
                $self->add_entry( $str, $line );
            };
        }

        my $p = Locale::Maketext::Extract::Plugin::TextTemplate::Parser->new;
        while (m/\G((.*?)^(?:START|END)[A-Z]+$)/smg) {
            my ($str) = ($2);
            $line += ( () = ( $1 =~ /\n/g ) );    # cryptocontext!
            $p->parse($str);
            $p->eof;
        }
        $_ = '';
    }

}


1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Locale::Maketext::Extract::Plugin::TextTemplate - Text::Template format parser

=head1 VERSION

version 1.00

=head1 SYNOPSIS

    $plugin = Locale::Maketext::Extract::Plugin::TextTemplate->new(
        $lexicon            # A Locale::Maketext::Extract object
        @file_types         # Optionally specify a list of recognised file types
    )

    $plugin->extract($filename,$filecontents);

=head1 DESCRIPTION

Extracts strings to localise from Text::Template files

=head1 SHORT PLUGIN NAME

    text

=head1 VALID FORMATS

Sentences between STARTxxx and ENDxxx are extracted individually.

=head1 KNOWN FILE TYPES



( run in 2.413 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )