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 translation_example.pl =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 https://www.googleapis.com/auth/cloud-translation =item https://www.googleapis.com/auth/cloud-platform =item assumes gapi.json configuration in working directory with scoped + project and user authorization =back Translation Service Specification: 'discoveryRestUrl' => 'https://translation.go +ogleapis.com/$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' => 'https://www.gstatic.co +m/images/branding/product/1x/googleg_32dp.png', 'x16' => 'https://www.gstatic.co +m/images/branding/product/1x/googleg_16dp.png' }, 'name' => 'translate', 'documentationLink' => 'https://code.google.c +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; ## https://cloud.google.com/translate/docs/reference/translate 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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.