NAME
Locale::TextDomain::OO::Extract - Extracts internationalization data as pot file
$Id: Extract.pm 254 2009-12-29 13:58:39Z steffenw $
$HeadURL: https://perl-gettext-oo.svn.sourceforge.net/svnroot/perl-gettext-oo/trunk/lib/Locale/TextDomain/OO/Extract.pm $
VERSION
0.04
DESCRIPTION
This module extracts internationalizations data and stores this in a pot file.
SYNOPSIS
use Locale::TextDomain::OO::Extract;
SUBROUTINES/METHODS
method init
This method is for initializing DBD::PO. How to initialize see DBD::PO.
BEGIN {
Locale::TextDomain::OO::Extract->init( qw(:plural) );
}
method new
All parameters are optional.
my $extractor = Locale::TextDomain::OO::Extract->new(
# prepare the file and the encoding
preprocess_code => sub {
my $content_ref = shift;
...
return;
},
# how to find such lines
start_rule => qr{__ n?p?x? \(}xms
# how to find the parameters
rules => [
[
# __( 'text'
# __x( 'text'
qr{__ (x?) \s* \( \s*}xms,
qr{\s*}xms,
# You can re-use the next reference.
# It is a subdefinition.
[
qr{'}xms,
qr{( (?: \\\\ \\\\ | \\\\ ' | [^'] )+ )}xms,
qr{'}xms,
],
],
# The next array reference describes an alternative
# and not a subdefinition.
'OR',
[
# next alternative e.g.
# __n( 'context' , 'text'
# __nx( 'context' , 'text'
...
],
],
# debug output for other rules than perl
run_debug => $boolean, # to check own writen rules
# how to map the parameters to pot file
parameter_mapping_code => sub {
my $parameter = shift;
# The chars after __ were stored to make a decision now.
my $context_parameter = shift @{$parameter};
return {
msgctxt => $context_parameter =~ m{p}xms
? $context_parameter
: undef,
msgid => scalar shift @{$parameter},
msgid_plural => scalar shift @{$parameter},
};
},
# where to store the pot file
pot_dir => './',
# how to store the pot file
# - The meaning of undef is ISO-8859-1 but use not Perl unicode.
# - Set 'ISO-8859-1' to have a ISO-8859-1 pot file and use Perl unicode.
# - Set 'UTF-8' to have a UTF-8 pot file and use Perl unicode.
# And so on.
pot_charset => undef,
# add some key value pairs to the header
# more see documentation of DBD::PO
pot_header => { ... },
);
method extract
The default pot_dir is "./".
Call
$extractor->extract('dir/filename.pl');
to extract "dir/filename.pl" to have a "$pot_dir/dir/filename.pl.pot".
Call
open my $file_handle, '<', 'dir/filename.pl'
or croak "Can no open file dir/filename.pl\n$OS_ERROR";
$extractor->extract('filename', $file_handle);
to extract "dir/filename.pl" to have a "$pot_dir/filename.pot".
method debug
Switch on the debug to see on STDERR how the rules are handled. Inherit of this class and write your own debug method if needed.
EXAMPLE
Inside of this distribution is a directory named example. Run this *.pl files.
DIAGNOSTICS
Error message in case of unknown parameters at method new.
Unknown parameter: ...
Undef is not a filename.
No file name given
There is a problem in opening the file to extract.
Can not open file ...
CONFIGURATION AND ENVIRONMENT
none
DEPENDENCIES
version
Carp
English
Clone
DBI
DBD::PO
dynamic require
INCOMPATIBILITIES
not known
BUGS AND LIMITATIONS
none
SEE ALSO
AUTHOR
Steffen Winkler
LICENSE AND COPYRIGHT
Copyright (c) 2009, Steffen Winkler <steffenw at cpan.org>
. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.