The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

I22r::Translate::Google - Google backend for I22r::Translate framework

SYNOPSIS

    I22r::Translate->config(
        'I22r::Translate::Google' => {
            ENABLED => 1,
            API_KEY => "your_required_API_key_goes_here",
            REFERER => "http://mywebsite.com/"
        }
    );

    $translation = I22r::Translate->translate_string(
        src => 'en', dest => 'es', text => 'hello world',
        quality => { 'I22r::Translate::Google' => 2.0 } );

DESCRIPTION

Invokes Google's translation webservice to translate content from one language to another.

You instruct the I22r::Translate package to use the Google backend by passing a key-value pair to the I22r::Translate::config method where the key is the string "I22r::Translate::Google" and the value is a hash reference with at least the following key-value pairs:

ENABLED => 0 | 1

Must be set to a true value for the Google backend to be enabled.

API_KEY => string

An API key is required to use the Google Translate web service. You can get an API key from https://code.google.com/apis/console (note: this is not a free service). (other note: if you can't get an API key from the above URL, but then you do figure out where to get one, let me know or file a bug report and I'll update these instructions).

Configuration for the Google backend also recognizes these options:

REFERER => URL

Sets a URL that will passed to the Google Translate service as your application's referer. If not set, this package will set the referer to http://just.doing.some.testing/.

timeout => integer

Stops a translation job after a certain number of seconds have passed.

callback => code reference or function name

A function to be invoked when the Google backend obtains a translation result. The function will be called with a single hash reference argument, containing the available data about the translation input and output.

filter => array reference

List of filters to use (see I22r::Translate::Filter) when sending text to the Google Translate webservice.

When you use the "translate_string" in I22r::Translate, "translate_list" in I22r::Translate, or "translate_hash" in I22r::Translate function, the I22r::Translate module will decide when to use the Google backend for translation. Most users do not need to know anything else about the methods in this package.

TODO

1. You typically make a GET request to the Google webservice, which has a limit of 2000 characters (that's 2000 URL encoded and UTF-8 encoded bytes, right?). If you use a POST request, you can send up to 5000 bytes. WWW::Google::Translate does this.
2. Provide a way to override the can_translate method and plug in your own opinion of how well Google translates between language pairs (ultimately, want to be able to do this for every backend).
3. Dynamically determine the list of languages supported by Google translate. Either that or release a new version of this module each time a language is added/deleted.

AUTHOR

Marty O'Brien, <mob@cpan.org>

SEE ALSO

WWW::Google::Translate, Lingua::Translate::Google, REST::Google::Translate, REST::Google::Translate2

LICENSE AND COPYRIGHT

Copyright 2012-2016 Marty O'Brien.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.