View on
Marty O'Brien > I22r-Translate > I22r::Translate::Google



Annotate this POD


Open  1
View/Report Bugs
Module Version: 0.96   Source  


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


        'I22r::Translate::Google' => {
            ENABLED => 1,
            API_KEY => "your_required_API_key_goes_here",
            REFERER => ""

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


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 (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:


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.


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.


Marty O'Brien, <>


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


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 for more information.

syntax highlighting: