Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'm currently refining WebService::GoogleAPI::Client module that is on CPAN and can help you do this if you wish to use Google Translate API.

Here's an example of translating from English to French.

#!/usr/bin/env perl use WebService::GoogleAPI::Client; use Data::Dumper qw (Dumper); use strict; use warnings; use feature 'say'; =head1 =head2 PRE-REQUISITES Setup a Google Project in the Google Console and add the Translate API + Library. You may need to enable billing to access Google Cloud Services. Setup an OAUTH Credential set and feed this into the CLI goauth included in WebService::GoogleAPI::Client and use the tool to authoris +e your user to access the project which will also create the local gapi. +json config. =over 2 =item =item =item assumes gapi.json configuration in working directory with scoped + project and user authorization =back Translation Service Specification: 'discoveryRestUrl' => 'https://translation.go$discovery/rest?version=v2', 'description' => 'Integrates text translation + into your website or application.', 'preferred' => $VAR1->{'items'}[0]{'preferred +'}, 'kind' => 'discovery#directoryItem', 'id' => 'translate:v2', 'version' => 'v2', 'title' => 'Cloud Translation API', 'icons' => { 'x32' => ' +m/images/branding/product/1x/googleg_32dp.png', 'x16' => ' +m/images/branding/product/1x/googleg_16dp.png' }, 'name' => 'translate', 'documentationLink' => ' +om/apis/language/translate/v2/getting_started.html' }, =cut ## assumes gapi.json configuration in working directory with scoped pr +oject and user authorization ## manunally sets the client user email to be the first in the gapi.js +on file my $gapi_client = WebService::GoogleAPI::Client->new( debug => 0, gapi +_json => 'gapi.json', debug=>1 ); my $aref_token_emails = $gapi_client->auth_storage->storage->get_token +_emails_from_storage; my $user = $aref_token_emails->[0]; $gapi_client->user( $user ); ## set to the first authorised user email + # my $list = $gapi_client->discover_all(); # say Dumper $list; # list available api endpoints #my $r = $gapi_client->api_query( api_endpoint_id => 'translate.langu +ages.list'); #say Dumper $r->json; ## my $r = $gapi_client->api_query( api_endpoint_id => 'translate.transl +ations.translate', options => { q=>'this is some text to transla +te into french', target => 'fr', format => 'text', } ); say Dumper $r->json; say $r->json->{data}{translations}[0]{translatedText};

In reply to Re: language translate by localshop
in thread language translate by bigup401

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2021-07-29 09:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found