view release on metacpan or search on metacpan
0.033
* Fix shareroot bug
* Update command help.
* Fix server command.
0.032
* Just update.
0.007
* Add --prompt option to `po auto` command.
Auto translate via Google Translate REST API:
Default backend is google translate REST API, This will translate zh\_TW.po file and translate msgid (en\_US)
to msgstr (zh\_TW):
$ po auto zh_TW --from en_US
$ po auto zh_CN --from en_US --to zh_CN
$ po auto zh_CN --from en_US --overwrite --prompt
$ po auto --backend google-rest --from en\_US --to zh\_TW
## Generate Static Dictionary File For Code
To generate dictionary hash in perl:
$ po gen pm
To generate dictionary hash in javascript (json):
inc/Module/AutoInstall.pm view on Meta::CPAN
}
elsif ( $arg =~ /^--test(?:only)?$/ ) {
$TestOnly = 1;
}
elsif ( $arg =~ /^--all(?:deps)?$/ ) {
$AllDeps = 1;
}
}
}
# overrides MakeMaker's prompt() to automatically accept the default choice
sub _prompt {
goto &ExtUtils::MakeMaker::prompt unless $AcceptDefault;
my ( $prompt, $default ) = @_;
my $y = ( $default =~ /^[Yy]/ );
print $prompt, ' [', ( $y ? 'Y' : 'y' ), '/', ( $y ? 'n' : 'N' ), '] ';
print "$default\n";
return $default;
}
# the workhorse
sub import {
my $class = shift;
my @args = @_ or return;
my $core_all;
inc/Module/AutoInstall.pm view on Meta::CPAN
map {
ref($_)
? ( ( ref($_) eq 'HASH' ) ? keys(%$_) : @{$_} )
: ''
}
map { +{@args}->{$_} }
grep { /^[^\-]/ or /^-core$/i } keys %{ +{@args} }
)[0]
);
# We want to know if we're under CPAN early to avoid prompting, but
# if we aren't going to try and install anything anyway then skip the
# check entirely since we don't want to have to load (and configure)
# an old CPAN just for a cosmetic message
$UnderCPAN = _check_lock(1) unless $SkipInstall;
while ( my ( $feature, $modules ) = splice( @args, 0, 2 ) ) {
my ( @required, @tests, @skiptests );
my $default = 1;
my $conflict = 0;
inc/Module/AutoInstall.pm view on Meta::CPAN
next unless @required;
my $mandatory = ( $feature eq '-core' or $core_all );
if (
!$SkipInstall
and (
$CheckOnly
or ($mandatory and $UnderCPAN)
or $AllDeps
or _prompt(
qq{==> Auto-install the }
. ( @required / 2 )
. ( $mandatory ? ' mandatory' : ' optional' )
. qq{ module(s) from CPAN?},
$default ? 'y' : 'n',
) =~ /^[Yy]/
)
)
{
push( @Missing, @required );
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
}
elsif ( !$SkipInstall
and $default
and $mandatory
and
_prompt( qq{==> The module(s) are mandatory! Really skip?}, 'n', )
=~ /^[Nn]/ )
{
push( @Missing, @required );
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
}
else {
$DisabledTests{$_} = 1 for map { glob($_) } @tests;
}
}
inc/Module/AutoInstall.pm view on Meta::CPAN
}
sub _update_to {
my $class = __PACKAGE__;
my $ver = shift;
return
if _version_cmp( _load($class), $ver ) >= 0; # no need to upgrade
if (
_prompt( "==> A newer version of $class ($ver) is required. Install?",
'y' ) =~ /^[Nn]/
)
{
die "*** Please install $class $ver manually.\n";
}
print << ".";
*** Trying to fetch it from CPAN...
.
inc/Module/AutoInstall.pm view on Meta::CPAN
*** Cannot bootstrap myself. :-( Installation terminated.
.
}
# check if we're connected to some host, using inet_aton
sub _connected_to {
my $site = shift;
return (
( _load('Socket') and Socket::inet_aton($site) ) or _prompt(
qq(
*** Your host cannot resolve the domain name '$site', which
probably means the Internet connections are unavailable.
==> Should we try to install the required module(s) anyway?), 'n'
) =~ /^[Yy]/
);
}
# check if a directory is writable; may create it on demand
sub _can_write {
inc/Module/AutoInstall.pm view on Meta::CPAN
mkdir( $path, 0755 ) unless -e $path;
return 1 if -w $path;
print << ".";
*** You are not allowed to write to the directory '$path';
the installation may fail due to insufficient permissions.
.
if (
eval '$>' and lc(`sudo -V`) =~ /version/ and _prompt(
qq(
==> Should we try to re-execute the autoinstall process with 'sudo'?),
((-t STDIN) ? 'y' : 'n')
) =~ /^[Yy]/
)
{
# try to bootstrap ourselves from sudo
print << ".";
*** Trying to re-execute the autoinstall process with 'sudo'...
inc/Module/AutoInstall.pm view on Meta::CPAN
return
unless system( 'sudo', $^X, $0, "--config=$config",
"--installdeps=$missing" );
print << ".";
*** The 'sudo' command exited with error! Resuming...
.
}
return _prompt(
qq(
==> Should we try to install the required module(s) anyway?), 'n'
) =~ /^[Yy]/;
}
# load a module and return the version it reports
sub _load {
my $mod = pop; # class/instance doesn't matter
my $file = $mod;
inc/Module/Install/Makefile.pm view on Meta::CPAN
BEGIN {
$VERSION = '1.00';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
sub Makefile { $_[0] }
my %seen = ();
sub prompt {
shift;
# Infinite loop protection
my @c = caller();
if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) {
die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])";
}
# In automated testing or non-interactive session, always use defaults
if ( ($ENV{AUTOMATED_TESTING} or -! -t STDIN) and ! $ENV{PERL_MM_USE_DEFAULT} ) {
local $ENV{PERL_MM_USE_DEFAULT} = 1;
goto &ExtUtils::MakeMaker::prompt;
} else {
goto &ExtUtils::MakeMaker::prompt;
}
}
# Store a cleaned up version of the MakeMaker version,
# since we need to behave differently in a variety of
# ways based on the MM version.
my $makemaker = eval $ExtUtils::MakeMaker::VERSION;
# If we are passed a param, do a "newer than" comparison.
# Otherwise, just return the MakeMaker version.
lib/App/I18N.pm view on Meta::CPAN
Auto translate via Google Translate REST API:
Default backend is google translate REST API, This will translate zh\_TW.po file and translate msgid (en\_US)
to msgstr (zh\_TW):
$ po auto zh_TW --from en_US
$ po auto zh_CN --from en_US --to zh_CN
$ po auto zh_CN --from en_US --overwrite --prompt
$ po auto --backend google-rest --from en\_US --to zh\_TW
=cut
lib/App/I18N/Command.pm view on Meta::CPAN
my ($pkg, $cmd, @args) = @_;
local *ARGV = [$cmd, @args];
my $ret = eval {
$pkg->dispatch();
};
if( $@ ) {
warn $@;
}
}
sub prompt {
my ( $self, $msg, $default ) = @_;
$default ||= "Y";
print STDERR $msg;
my $ans = <STDIN>;
chomp($ans);
$ans =~ s{[\r\n]}{}g;
$ans ||= $default;
lib/App/I18N/Command/Auto.pm view on Meta::CPAN
sub options {
(
'f|from=s' => 'from',
't|to=s' => 'to',
'backend=s' => 'backend',
'locale' => 'locale',
'verbose' => 'verbose',
'msgstr' => 'msgstr', # translate from existing msgstr instead of translating from msgid.
'overwrite' => 'overwrite', # overwrite existing msgstr
'p|prompt' => 'prompt',
)
}
sub run {
my ( $self , $lang ) = @_;
my $logger = $self->logger();
unless( $lang ) {
lib/App/I18N/Command/Auto.pm view on Meta::CPAN
$logger->info( "Retrying ..." );
}
if ($res->responseStatus == 200) {
my $translated = $res->responseData->translatedText;
$logger->info( "translated: " . encode_utf8( $translated ) );
if( ($msgstr && $self->{overwrite})
|| ! $msgstr ) {
if( $self->{prompt} ) {
my $ans = $self->prompt( "Apply this ? (Y/n)" );
next NEXT_MSGID if $ans =~ /^\s*n\s*$/i;
if ( $ans !~ /^\s*y\s*$/i ) {
print STDERR qq|Applying "$ans"\n|;
# it's user typed msgstr
$ext->set_msgstr( $i, $ans );
next NEXT_MSGID;
}
}
print STDERR qq|Applying "$translated"\n|;
lib/App/I18N/Command/Auto.pm view on Meta::CPAN
=head1 DESCRIPTION
auto - auto translate po files.
=head1 OPTIONS
--from [lang]
--to [lang]
--backend [backend]
--locale
--prompt
--overwrite
--msgstr
--verbose
Translate zh_CN.po from en_US to zh_TW
po auto zh_CN --from en_US --to zh_TW
po auto zh_CN --from en_US --overwrite --prompt
=cut
lib/App/I18N/Command/Initdb.pm view on Meta::CPAN
) }
sub run {
my ($self,$dbname) = @_;
$dbname ||= 'i18n.sqlite';
my $dbpath = File::Spec->join( $ENV{HOME} , $dbname );
if ( -e $dbpath ) {
my $ans = $self->prompt( "Database $dbname exists, replace it ? (N/y)", 'n');
return if( $ans =~ /n/i );
}
unlink( $dbpath );
my $db = App::I18N::DB->new( path => $dbpath );
$db->init_schema();
$db->close();
print "Database $dbname ($dbpath) created.\n";
}