Locale::Maketext::Extract::Plugin::Base(3pm)

Locale::Maketext::Extract::Plugin::Base3pm

Base module for format parser plugins

Usage

    package My::Parser::Plugin;
    use base qw(Locale::Maketext::Extract::Plugin::Base);
    sub file_types {
        return [qw( ext ext2 )]
    }
    sub extract {
        my $self = shift;
        local $_ = shift;
        my $line = 1;
        while (my $found = $self->routine_to_extract_strings) {
            $self->add_entry($str,[$filename,$line,$vars])
        }
        return;
    }

Version

version 1.00

Overview

All format parser plugins in Locale::Maketext::Extract inherit from Locale::Maketext::Extract::Plugin::Base.

If you want to write your own custom parser plugin, you will need to inherit from this module, and provide file_types() and extract() methods, as shown above.

Methods

new()
    $plugin = My::Parser->new(
        @file_types         # Optionally specify a list of recognised file types
    )
add_entry()
    $plugin->add_entry($str,$line,$vars)
entries()
    $entries = $plugin->entries;
clear()
    $plugin->clear

Clears all stored entries.

file_types()
    @default_file_types = $plugin->file_types

Returns a list of recognised file types that your module knows how to parse.

Each file type can be one of:

•

A plain string

   'pl'  => base filename is matched against qr/\.pl$/
   '*'   => all files are accepted
•

A regex

   qr/\.tt2?\./ => base filename is matched against this regex
•

A codref

    sub {}  => this codref is called as $coderef->($base_filename,$path_to_file)
               It should return true or false
extract()
    $plugin->extract($filecontents);

extract() is the method that will be called to process the contents of the current file.

When it finds a string that should be extracted, it should call

   $self->add_entry($string,$line,$vars])

where $vars refers to any arguments that are being passed to the localise function. For instance:

   l("You found [quant,_1,file,files]",files_found)
     string: "You found [quant,_1,file,files]"
     vars  : (files_found)

IMPORTANT: a single plugin instance is used for all files, so if you plan on storing state information in the $plugin object, this should be cleared out at the beginning of extract()

known_file_type()
    if ($plugin->known_file_type($filename_with_path)) {
        ....
    }

Determines whether the current file should be handled by this parser, based either on the list of file_types specified when this object was created, or the default file_types specified in the module.

Releases

9 releases since Debian 6.0 (Squeeze); the text changed 5 times.

  1. 6.0
  2. 7
  3. 8–10
  4. 11
  5. 12–13
  6. Arch

Authors

Clinton Gormley [DRTECH] <[email protected]>

Authors

•

Clinton Gormley <[email protected]>

•

Audrey Tang <[email protected]>

From perl-locale-maketext-lexicon 1.00-5 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.