Ok, for anyone interested - its cos the JSON module needed to explicitly use the utf8 functions JSON->new->utf8 , and then also decode(). I've changed it to this, and it works perfectly now <G>
sub Do_Translate {
my ($from,$to,$string) = @_;
my $url = "https://www.googleapis.com/language/translate/v2?key=$k
+ey&q=$string&source=$from&target=$to";
# print "getting URL: $url \n";
my $ua = LWP::UserAgent->new();
my $body = $ua->get($url);
my $json = JSON->new->utf8;
my $value = $json->decode( $body->decoded_content );
print "GOT: $value->{data}->{translations}[0]->{translatedText} \n
+";
return utf8($value->{data}->{translations}[0]->{translatedText})->
+latin1;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.