1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
=encoding utf8
=head1 NAME
Log::Report::Lexicon::POT - manage PO files
=head1 INHERITANCE
Log::Report::Lexicon::POT
is a Log::Report::Lexicon::Table
=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('msgid');
my $po = $pot->msgid($msgid, $msgctxt);
print $pot->nrPlurals;
print $pot->msgstr('msgid', 3);
print $pot->msgstr($msgid, 3, $msgctxt);
$pot->write; # update the file
# fill the table, by calling the next a lot
my $po = Log::Report::Lexicon::PO->new(...);
$pot->add($po);
# creating a PO table
$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 record will be represented by a
L<Log::Report::Lexicon::PO|Log::Report::Lexicon::PO>.
Extends L<"DESCRIPTION" in Log::Report::Lexicon::Table|Log::Report::Lexicon::Table/"DESCRIPTION">.
=head1 METHODS
Extends L<"METHODS" in Log::Report::Lexicon::Table|Log::Report::Lexicon::Table/"METHODS">.
=head2 Constructors
Extends L<"Constructors" in Log::Report::Lexicon::Table|Log::Report::Lexicon::Table/"Constructors">.
=over 4
=item Log::Report::Lexicon::POT-E<gt>B<new>(%options)
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 'UTF-8'
date now
filename undef
index {}
nr_plurals 2
plural_alg n!=1
plural_forms <constructed from nr_plurals and plural_alg>
textdomain <required>
version undef
=over 2
=item charset => STRING
The charset to be used for the createed file. It is unwise to use anything
else than 'UTF-8', but allowed. Before [1.09] this option was required.
=item date => STRING
Overrule the date which is included in the generated header.
=item filename => STRING
Specify an output filename. The name can also be specified when
L<write()|Log::Report::Lexicon::POT/"Constructors"> is called.
=item index => HASH
A set of translations (L<Log::Report::Lexicon::PO|Log::Report::Lexicon::PO> objects),
with msgid as key.
=item nr_plurals => INTEGER
The number of translations each of the translation with plural form
need to have.
=item plural_alg => EXPRESSION
The algorithm to be used to calculate which translated msgstr to use.
=item plural_forms => RULE
[0.992] When this option is used, it overrules C<nr_plurals> and
C<plural_alg>. The RULE should be a full "Plural-Forms" field.
=item textdomain => STRING
The package name, used in the directory structure to store the
PO files.
=item version => STRING
=back
=item Log::Report::Lexicon::POT-E<gt>B<read>($filename, %options)
Read the POT information from $filename.
-Option --Default
charset <required>
=over 2
=item charset => STRING
The character-set which is used for the file. You must specify
this explicitly.
=back
=item $obj-E<gt>B<write>( [$filename|$fh], %options )
When you pass an open $fh, 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.
-Option --Default
only_active false
=over 2
=item only_active => BOOLEAN
[1.02] Do not write records which do have a translation, but where the
msgid has disappeared from the sources. By default, these records are
commented out (marked with '#~') but left in the file.
=back
=back
=head2 Attributes
Extends L<"Attributes" in Log::Report::Lexicon::Table|Log::Report::Lexicon::Table/"Attributes">.
=over 4
=item $obj-E<gt>B<charset>()
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.
=item $obj-E<gt>B<filename>()
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">.
=item $obj-E<gt>B<index>()
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.
=item $obj-E<gt>B<language>()
Returns the language code, which is derived from the filename.
=back
=head2 Managing PO's
Extends L<"Managing PO's" in Log::Report::Lexicon::Table|Log::Report::Lexicon::Table/"Managing PO's">.
=over 4
=item $obj-E<gt>B<keepReferencesTo>($table)
Remove all references which are not found as key in the hash $table.
Returns the number of references left.
=item $obj-E<gt>B<removeReferencesTo>($filename)
Remove all the references to the indicate $filename from all defined
translations. Returns the number of refs left.
=item $obj-E<gt>B<stats>()
Returns a HASH with some statistics about this POT table.
=item $obj-E<gt>B<updated>( [$date] )
Replace the "PO-Revision-Date" with the specified $date, or the current
moment.
=back
=head3 Translation
Extends L<"Translation" in Log::Report::Lexicon::Table|Log::Report::Lexicon::Table/"Translation">.
=over 4
=item $obj-E<gt>B<msgid>( STRING, [$msgctxt] )
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.
=item $obj-E<gt>B<msgstr>( $msgid, [$count, [$msgctxt]] )
Returns the translated string for $msgid. When $count is not specified or
C<undef>, the translation string related to "1" is returned.
=back
=head3 Administration
Extends L<"Administration" in Log::Report::Lexicon::Table|Log::Report::Lexicon::Table/"Administration">.
=over 4
=item $obj-E<gt>B<add>($po)
Add the information from a $po into this POT. If the msgid of the $po
is already known, that is an error.
=item $obj-E<gt>B<header>( [$field, [$content]] )
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.
=item $obj-E<gt>B<nrPlurals>()
Inherited, see L<Log::Report::Lexicon::Table/"Administration">
=item $obj-E<gt>B<pluralIndex>($count)
Inherited, see L<Log::Report::Lexicon::Table/"Administration">
=item $obj-E<gt>B<setupPluralAlgorithm>()
Inherited, see L<Log::Report::Lexicon::Table/"Administration">
=item $obj-E<gt>B<translations>( [$active] )
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
=head1 DIAGNOSTICS
=over 4
=item Error: no filename or file-handle specified for PO
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.
=item Error: only acceptable parameter is 'ACTIVE'
=item Error: textdomain parameter is required
=back
=head1 SEE ALSO
This module is part of Log-Report-Lexicon distribution version 1.12,
built on April 18, 2025. Website: F<http://perl.overmeer.net/CPAN/>
=head1 LICENSE
Copyrights 2007-2025 by [Mark Overmeer <markov@cpan.org>]. 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://dev.perl.org/licenses/>
|