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


REST-Google documentation  | view source Contained in the REST-Google distribution.

Index


NAME

Top

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

SYNOPSIS

Top

	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;

DESCRIPTION

Top

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

METHODS

Top

__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

SEE ALSO

Top

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

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

LICENSE AND COPYRIGHT

Top


REST-Google documentation  | view source Contained in the REST-Google distribution.