| Locale-Maketext-Extract-DBI documentation | Contained in the Locale-Maketext-Extract-DBI distribution. |
Locale::Maketext::Extract::DBI - Extract translation keys from a database
my $extractor = Locale::Maketext::Extract::DBI->new;
$extract->extract( %options );
This module extracts translation keys from a database table.
Creates a new Locale::Maketext::Extract::DBI instance.
The main method for extraction. Take a list of options to pass to
Locale::Maketext::Extract and extract_dbi.
Connects to the database, runs the query and stuffs the results in to
the $extractor.
Copyright 2006 by Brian Cassidy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Locale-Maketext-Extract-DBI documentation | Contained in the Locale-Maketext-Extract-DBI distribution. |
package Locale::Maketext::Extract::DBI; use strict; use warnings; use Locale::Maketext::Extract; use DBI; use Cwd; our $VERSION = '0.01';
sub new { my $class = shift; return bless {}, $class; }
sub extract { my $self = shift; my %options = @_; my $extractor = Locale::Maketext::Extract->new; my $output = $options{ o } || ( $options{ d } || 'messages' ) . '.po' ; my $cwd = getcwd; $extractor->read_po( $output ) if -r $output and -s _; $self->extract_dbi( $extractor, %options ); $extractor->compile; chdir( $options{ p } || '.' ); $extractor->write_po( $output ); chdir $cwd; }
sub extract_dbi { my( $self, $extractor, %options ) = @_; my $dbh = DBI->connect( ( map{ $options{ $_ } } qw( dsn username password ) ), { RaiseError => 1 } ); my $query = $options{ query }; my $results = $dbh->selectall_arrayref( $query ); for( 0..@$results - 1 ) { $extractor->add_entry( $results->[ $_ ]->[ 0 ] => [ "dbi:$query", $_ + 1] ); } }
1;