App-I18N
view release on metacpan or search on metacpan
lib/App/I18N.pm view on Meta::CPAN
sub guess_podir {
my ($class,$cmd) = @_;
my $podir;
$podir = 'po' if -e 'po';
$podir = 'locale' , $cmd->{locale} = 1 if -e 'locale';
$podir ||= 'locale' if $cmd->{locale};
$podir ||= 'po';
return $podir;
}
sub get_po_path {
my ( $self, $podir, $lang, $is_locale ) = @_;
my $pot_name = App::I18N->pot_name;
my $path;
if ($is_locale) {
$path = File::Spec->join( $podir, $lang . ".po" );
}
else {
$path = File::Spec->join( $podir, 'locale', $lang, 'LC_MESSAGES', $pot_name . ".po" );
}
return $path;
}
sub update_catalogs {
my ($self,$podir , $cmd ) = @_;
my @catalogs = grep !m{(^|/)(?:\.svn|\.git)/},
File::Find::Rule->file
->name('*.po')->in( $podir);
my $logger = App::I18N->logger;
unless ( @catalogs ) {
$logger->error("You have no existing message catalogs.");
$logger->error("Run `po lang <lang>` to create a new one.");
$logger->error("Read `po help` to get more info.");
return
}
foreach my $catalog (@catalogs) {
$self->update_catalog( $catalog , $cmd );
}
}
# _('Internationalization')
# _('Translate me')
1;
__END__
=head1 NAME
App::I18N - I18N utility.
=head1 DESCRIPTION
I18N management utility, provides an command-line interface to parse /
translate / update mo file i18n messages.
App::I18N borrows some good stuff from L<Jifty::I18N> and L<Jifty::Script::Po>
and tries to provide a general po management script for all frameworks |
applications.
=head1 USAGE
=head2 Basic flow
=head3 Basic po file manipulation:
parse strings from `lib` path:
$ cd app
$ po parse lib
this will generate:
po/app.pot
please modify the CHARSET in po/app.pot.
... modify CHARSET ...
create new language file (po file):
po lang en
po lang fr
po lang ja
po lang zh_TW
this generates:
po/en.po
po/fr.po
po/ja.po
po/zh_TW.po
... do translation here
when you added more message in your application. you might need to update po
messages, but you dont have to delete/recreate these po files, you can just parse your messages again
all of your translations will be kept. eg:
$ po parse lib
... do translation again ...
### Generate locale and mo file for php-gettext or anyother gettext i18n app:
parse strings from `.` path and use --locale (locale directory structure):
$ cd app
$ po parse --locale .
this will generate:
po/app.pot
please modify the CHARSET in po/app.pot.
... modify CHARSET ...
( run in 1.753 second using v1.01-cache-2.11-cpan-e1769b4cff6 )