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 line in the file.

read()

Reads and parses a file.

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.

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.

msgstr

The translation, if any.

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 an "empty" function to return an empty .po file.

We need a "setdate" function to reset the date of a .po file.

We need to support encodings other than UTF-8.

We need a "readString" function to parse strings rather than files.

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.