#!/usr/bin/perl -w use 5.011; use WWW::Google::Translate; use Config::Tiny; use Data::Dumper; use open OUT => ':encoding(UTF-8)', ':std'; use Path::Tiny; my $ini_path = qw( /home/bob/Documents/html_template_data/3.values.ini ); say "ini path is $ini_path"; my $tempfile = Path::Tiny->tempfile(TEMPLATE => 'trans_XXXXXX', suffix => '.txt'); my $string_temp = $tempfile->stringify; say "save file is $string_temp"; my $sub_hash = "google"; my $Config = Config::Tiny->new; $Config = Config::Tiny->read( $ini_path, 'utf8' ); #say Dumper $Config; my $von = 'en'; my $zu = 'ru'; # -> is optional between brackets my $key = $Config->{$sub_hash}{'api_key_1'}; my $wgt = WWW::Google::Translate->new( { key => $key, default_source => $von, default_target => $zu, } ); my $r = $wgt->translate( { q => 'I wave my private parts at your aunties, you cheesy lot of second hand electric donkey-bottom biters.' } ); my $result = ""; for my $trans_rh ( @{ $r->{data}->{translations} } ) { $result = $trans_rh->{translatedText}; print $trans_rh->{translatedText}, "\n"; } say Dumper $r; my $wgt2 = WWW::Google::Translate->new( { key => $key, default_source => $zu, default_target => $von, cache_file => $string_temp, } ); my $s = $wgt2->translate( { q => $result} ); for my $trans_rh ( @{ $s->{data}->{translations} } ) { print $trans_rh->{translatedText}, "\n"; } say Dumper $s; say "------";