The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Locale::PO::Callback - parse gettext source files

AUTHOR

Thomas Thurman <thomas@thurman.org.uk>

SYNOPSIS

  use Locale::PO::Callback;

  sub callback {
     # ...
  }

  my $lpc = Locale::PO::Callback->new(\&callback);
  $lpc->read('test.po');

DESCRIPTION

This module parses the .po files used by GNU gettext to hold translation catalogues. It takes one parameter, a coderef, and calls it repeatedly with a description of every item in the file. This enables chains of filters to be produced, as is commonly done with XML processing.

METHODS

new(callback)

Creates an object. The callback parameter is a coderef which will be called with a description of every item in the file.

read_file(filename)

Reads and parses a file.

read_string(string)

Parses a string.

read(filename_or_string, is_string)

Reads and parses a file or a string, depending on the is_string argument.

create_empty()

Behaves as though we had just read in an empty file, with default headers.

OTHER THINGS

rebuilder(coderef)

Given a coderef, this function returns a function which can be passed as a callback to this class's constructor. The coderef will be called with strings which, if concatenated, make a .po file equivalent to the source .po file.

In pipeline terms, this function produces sinks.

set_date(coderef)

Given a coderef, this function returns a function which can be passed as a callback to this class's constructor. The function will pass its parameters through to the coderef unchanged, except for headers, when the file date will be changed to the current system date.

In pipeline terms, this function produces filters.

PARAMETERS TO THE CALLBACK

type

"header", "translation", or "other" (which last should never appear in ordinary use).

comments

An arrayref of comments which appear before this item.

flags

A hashref of the flags of this item (such as "fuzzy").

locations

An arrayref of arrayrefs, the first item being a filename and the second being a line number.

msgid

The source message, in its singular form.

msgid_plural

The source message, in its plural form. This is usually empty.

msgstr

The translation, if any, unless this translation has plural forms, in which case see the next entry.

msgstr[0] (etc)

Variations on the translation for different plural forms.

msgctxt

The "context" of the translation. Rarely filled in.

headers

A hashref of headers, mapping fieldnames to values. The keys are lowercased.

header_order

An arrayref of the header fieldnames, in the casing and order in which they were found.

FUTURE EXPANSION

We need to support encodings other than UTF-8.

This documentation was written in a bit of a rush.

COPYRIGHT

This Perl module is copyright (C) Thomas Thurman, 2010. This is free software, and can be used/modified under the same terms as Perl itself.