=head1 NAME Log::Report::Lexicon::POT - manage PO files =head1 SYNOPSIS # this is usually not for end-users, See ::Extract::PerlPPI # using a PO table my $pot = Log::Report::Lexicon::POT ->read('po/nl.po', charset => 'utf-8') or die; my $po = $pot->msgid(''); print $pot->nrPlurals; print $pot->msgstr('msgid', 3); $pot->write; # creating a PO table my $po = Log::Report::Lexicon::PO->new(...); $pot->add($po); $pot->write('po/nl.po') or die; =head1 DESCRIPTION This module is reading, extending, and writing POT files. POT files are used to store translations in humanly readable format for most of existing translation frameworks, like GNU gettext and Perl's Maketext. If you only wish to access the translation, then you may use the much more efficient L<Log::Report::Lexicon::POTcompact|Log::Report::Lexicon::POTcompact>. The code is loosely based on Locale::PO, by Alan Schwartz. The coding style is a bit off the rest of C<Log::Report>, and there was a need to sincere simplification. Each PO object will be represented by a L<Log::Report::Lexicon::PO|Log::Report::Lexicon::PO>. =head1 METHODS =head2 Constructors Log::Report::Lexicon::POT-E<gt>B<new>(OPTIONS) =over 4 Create a new POT file. The initial header is generated for you, but it can be changed using the L<header()|Log::Report::Lexicon::POT/"Managing PO's"> method. Option --Default charset <required> date now filename undef index {} nr_plurals 2 plural_alg n!=1 textdomain <required> version undef . charset => STRING =over 4 The character-set which is used for the output. =back . date => STRING =over 4 Overrule the date which is included in the generated header. =back . filename => STRING =over 4 Specify an output filename. The name can also be specified when L<write()|Log::Report::Lexicon::POT/"Constructors"> is called. =back . index => HASH =over 4 A set of translations (L<Log::Report::Lexicon::PO|Log::Report::Lexicon::PO> objects), with msgid as key. =back . nr_plurals => INTEGER =over 4 The number of translations each of the translation with plural form need to have. =back . plural_alg => EXPRESSION =over 4 The algorithm to be used to calculate which translated msgstr to use. =back . textdomain => STRING =over 4 The package name, used in the directory structure to store the PO files. =back . version => STRING =back Log::Report::Lexicon::POT-E<gt>B<read>(FILENAME, OPTIONS) =over 4 Read the POT information from FILENAME. Option --Default charset <required> . charset => STRING =over 4 The character-set which is used for the file. You must specify this explicitly, while it cannot be trustfully detected automatically. =back =back $obj-E<gt>B<write>([FILENAME|FILEHANDLE], OPTIONS) =over 4 When you pass an open FILEHANDLE, you are yourself responsible that the correct character-encoding (binmode) is set. When the write followed a L<read()|Log::Report::Lexicon::POT/"Constructors"> or the filename was explicitly set with L<filename()|Log::Report::Lexicon::POT/"Attributes">, then you may omit the first parameter. =back =head2 Attributes $obj-E<gt>B<charset> =over 4 The character-set to be used for reading and writing. You do not need to be aware of Perl's internal encoding for the characters. =back $obj-E<gt>B<filename> =over 4 Returns the FILENAME, as derived from L<read()|Log::Report::Lexicon::POT/"Constructors"> or specified during initiation with L<new(filename)|Log::Report::Lexicon::POT/"Constructors">. =back $obj-E<gt>B<index> =over 4 Returns a HASH of all defined PO objects, organized by msgid. Please try to avoid using this: use L<msgid()|Log::Report::Lexicon::POT/"Managing PO's"> for lookup and L<add()|Log::Report::Lexicon::POT/"Managing PO's"> for adding translations. =back =head2 Managing PO's $obj-E<gt>B<add>(PO) =over 4 Add the information from a PO into this POT. If the msgid of the PO is already known, that is an error. =back $obj-E<gt>B<header>([FIELD, [CONTENT]]) =over 4 The translation of a blank MSGID is used to store a MIME header, which contains some meta-data. When only a FIELD is specified, that content is looked-up (case-insensitive) and returned. When a CONTENT is specified, the knowledge will be stored. In latter case, the header structure may get created. When the CONTENT is set to C<undef>, the field will be removed. =back $obj-E<gt>B<msgid>(STRING) =over 4 Lookup the L<Log::Report::Lexicon::PO|Log::Report::Lexicon::PO> with the STRING. If you want to add a new translation, use L<add()|Log::Report::Lexicon::POT/"Managing PO's">. Returns C<undef> when not defined. =back $obj-E<gt>B<msgstr>(MSGID, [COUNT]) =over 4 Returns the translated string for MSGID. When not specified, COUNT is 1. =back $obj-E<gt>B<nrPlurals> =over 4 Returns the number of plurals, when not known then '2'. =back $obj-E<gt>B<pluralIndex>(COUNT) =over 4 Returns the msgstr index used to translate a value of COUNT. =back $obj-E<gt>B<removeReferencesTo>(FILENAME) =over 4 Remove all the references to the indicate FILENAME from all defined translations. Returns the number of refs left. =back $obj-E<gt>B<stats> =over 4 Returns a HASH with some statistics about this POT table. =back $obj-E<gt>B<translations>([ACTIVE]) =over 4 Returns a list with all defined L<Log::Report::Lexicon::PO|Log::Report::Lexicon::PO> objects. When the string C<ACTIVE> is given as parameter, only objects which have references are returned. =back $obj-E<gt>B<updated>([DATE]) =over 4 Replace the "PO-Revision-Date" with the specified DATE, or the current moment. =back =head1 DIAGNOSTICS Error: charset parameter is required =over 4 =back Error: no filename or file-handle specified for PO =over 4 When a PO file is written, then a filename or file-handle must be specified explicitly, or set beforehand using the L<filename()|Log::Report::Lexicon::POT/"Attributes"> method, or known because the write follows a L<read()|Log::Report::Lexicon::POT/"Constructors"> of the file. =back Error: only acceptable parameter is 'ACTIVE' =over 4 =back Error: textdomain parameter is required =over 4 =back =head1 SEE ALSO This module is part of Log-Report distribution version 0.07, built on June 20, 2007. Website: F<http://perl.overmeer.net/log-report/> =head1 LICENSE Copyrights 2007 by Mark Overmeer. For other contributors see ChangeLog. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See F<http://www.perl.com/perl/misc/Artistic.html>