App-I18N

 view release on metacpan or  search on metacpan

lib/App/I18N/DB.pm  view on Meta::CPAN

            lang   => $row->{lang},
            msgid  => $row->{msgid},
            msgstr => $row->{msgstr},
        };
    }
    return \@result;
}


sub get_langlist {
    my $self = shift;
    my $sth = $self->dbh->prepare("select distinct lang from po_string;");
    $sth->execute();
    my $hashref = $sth->fetchall_hashref('lang');
    $sth->finish;
    return keys %$hashref;
}

sub write_to_pofile {
    # XXX:

}

sub import_lexicon {
    my ( $self , $lang , $lex ) = @_;
    while ( my ( $msgid, $msgstr ) = each %$lex ) {
        $self->insert( $lang , $msgid , $msgstr );
    }
}


sub import_po {
    my ( $self, $lang, $pofile ) = @_;
    my $lme = App::I18N->lm_extract;
    $lme->read_po($pofile) if -f $pofile && $pofile !~ m/pot$/;
    $self->import_lexicon( $lang , $lme->lexicon );
}

sub export_lexicon {
    my ($self) = @_;
    my $lexicon;


    return $lexicon;
}

sub export_po {
    my ( $self , $lang , $pofile ) = @_;
    my $list = $self->get_entry_list( $lang );
    my $lexicon =  {
        map { $_->{msgid} => encode_utf8 $_->{msgstr}; } @$list
    };
    my $lme = App::I18N->lm_extract;
    $lme->set_lexicon( $lexicon );
    $lme->write_po($pofile);
}

=pod
package MsgEntry;
use Any::Moose;
use JSON::XS;
use overload 
    '""' => \&to_string,
    '%{}' => \&to_hash;


has id => ( is => 'rw', isa => 'Int' );
has lang  => ( is => 'rw' , isa => 'Str' );
has msgid => ( is => 'rw' , isa => 'Str' );
has msgstr => ( is => 'rw' , isa => 'Str' );

sub to_hash {
    my $self = shift;
    return (
        id       => $self->id,
        lang     => $self->lang,
        msgid    => $self->msgid,
        msgstr   => $self->msgstr,
    );
}

sub to_string {
    my $self = shift;
    return encode_json( { $self->to_hash } );
}
=cut


1;



( run in 0.487 second using v1.01-cache-2.11-cpan-39bf76dae61 )