Skip to content

Commit

Permalink
Improve verbose message
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Mar 24, 2011
1 parent edeaea1 commit 1fc49ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
3 changes: 3 additions & 0 deletions lib/App/I18N/Command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ sub prompt {
print STDERR $msg;
my $ans = <STDIN>;
chomp($ans);
$ans =~ s{[\r\n]}{}g;

$ans ||= $default;

return $ans;
}

Expand Down
27 changes: 13 additions & 14 deletions lib/App/I18N/Command/Auto.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ sub run {
# ($from_lang_s) = ( $from_lang =~ m{^([a-z]+)(_\w+)?} );
# ($to_lang_s) = ( $to_lang =~ m{^([a-z]+)(_\w+)?} );

$logger->info( "Translating: $from_lang_s => $to_lang_s" );

$logger->info( "Initialing REST::Google" );
REST::Google::Translate->http_referer('http://google.com');

binmode STDERR, ":utf8";


NEXT_MSGID:
for my $i ($ext->msgids()) {
my $msgid = $i;
Expand All @@ -94,20 +98,20 @@ NEXT_MSGID:
# translate from msgstr
$i = $msgstr if $msgstr && $self->{msgstr};

$logger->info( "msgid: $msgid");
$logger->info( "msgstr: $msgstr" ) if $msgstr;
$logger->info( "tranlating from msgstr" ) if $self->{msgstr};
$logger->info( "$from_lang_s => $to_lang_s" );
$logger->info( "********" );
$logger->info( " msgid: $msgid");
$logger->info( " msgstr: $msgstr" ) if $msgstr;

$logger->info( " tranlating from msgstr" ) if $self->{msgstr};
$logger->info( " tranlating from msgid" ) if ! $self->{msgstr};

my $retry = 1;
while($retry--) {
my $res;
eval {
$res = REST::Google::Translate->new(
q => $i,
langpair => $from_lang_s . '|' . $to_lang_s );


q => $i,
langpair => $from_lang_s . '|' . $to_lang_s );
};

if( $@ ) {
Expand All @@ -119,15 +123,10 @@ NEXT_MSGID:

if ($res->responseStatus == 200) {
my $translated = $res->responseData->translatedText;
$logger->info( "[$translated]" );
$logger->info( "translated: " . encode_utf8( $translated ) );

if( ($msgstr && $self->{overwrite})
|| ! $msgstr ) {
if( $msgstr ) {
$logger->info( encode_utf8(" Translation overwrited: [$i] => [$translated]") );
} else {
$logger->info( encode_utf8(" Translation: [$i] => [$translated]" ) );
}

if( $self->{prompt} ) {
my $ans = $self->prompt( "Apply this ? (Y/n)" );
Expand Down

0 comments on commit 1fc49ee

Please sign in to comment.