GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
REST::Google::Translate(3) User Contributed Perl Documentation REST::Google::Translate(3)

REST::Google::Translate - OO interface to Google Translate (aka Languages) API

        use REST::Google::Translate;

        REST::Google::Translate->http_referer('http://example.com');

        my $res = REST::Google::Translate->new(
                q => 'hello world',
                langpair => 'en|it'
        );

        die "response status failure" if $res->responseStatus != 200;

        my $translated = $res->responseData->translatedText;

        printf "Italian translation: %s\n", $translated;

"REST::Google::Translate" provides OO interface to Google REST (aka AJAX) API for languages translation.

__PACKAGE__->http_referer()
Get/set HTTP "Referer" header.

Note: Google says that you should supply a valid HTTP referer header each time you perform a request to their AJAX API, so "new()" raises warning unless referer is specified.

__PACKAGE__->new()
"q" argument should contain a phrase for translation. "langpair" is used to specify translation languages.

According to Google API documentation the langpair languages should be separated by "|" (pipe) sign. For complete list of language pairs and other arguments please refer to 'Google Translate AJAX API' documentation. E.g.:

        my $res = REST::Google::Translate->new(
                q => 'hello world',
                langpair => 'en|it'
        );
    

The code above will perform a following HTTP GET request:

        http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello%20world&langpair=en%7Cit
    

Note: You can left protocol version number unspecified while making your searches since "v=1.0" is passed by default.

responseData
To access translated text you should use "responseData" method as follows

        $translated_text = $res->responseData->translatedText
    

REST::Google - the base class for this module;

<http://code.google.com/apis/ajaxlanguage/documentation/#fonje> - Google Translate AJAX API documentation;

Copyright 2008, Eugen Sobchenko <ejs@cpan.org> and Sergey Sinkovskiy <glorybox@cpan.org>

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2022-04-09 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.