package translate; use 5.006; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( get_config get_trans get_from_lang get_to_lang reverse_trans); our $VERSION = '0.01'; =head1 SYNOPSIS use translate; my $config = get_config('path-to-ini-file', $sub_hash); my $from = get_from_lang(); my $to = get_to_lang(); my $trans_output_file = get_trans($input_file, $from, $to, $config); my $reverse = reverse_trans($trans_output_file, $to, $from, $config); =cut sub get_config { use Config::Tiny; use Data::Dumper; use open OUT => ':encoding(UTF-8)'; use Path::Tiny; use 5.011; my ( $ini_path, $sub_hash ) = @_; say "ini path is $ini_path"; say "sub_hash is $sub_hash"; my $Config = Config::Tiny->new; $Config = Config::Tiny->read( $ini_path, 'utf8' ); say Dumper $Config; my $key = $Config->{$sub_hash}{'api_key_1'}; return $key; } sub get_from_lang { use Path::Tiny; use 5.011; my $von = 'en'; # put your default here say "Would you like to see the possibilities?"; my $prompt1 = ; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { my $path_to_langs = path( "my_data", "lang_data", "1.langlist.txt" ); my $data = $path_to_langs->slurp_utf8; say "$data"; } my $prompt2; say "Would you like to change the from language?"; $prompt1 = ; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { say "enter new lang: "; $prompt2 = ; chomp $prompt2; $von = $prompt2; } return $von; } sub get_to_lang { use Path::Tiny; use 5.011; my $zu = 'ru'; # put your default here say "Would you like to see the possibilities?"; my $prompt1 = ; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { my $path_to_langs = path( "my_data", "lang_data", "1.langlist.txt" ); my $data = $path_to_langs->slurp_utf8; say "$data"; } my $prompt2; say "Would you like to change the from language?"; $prompt1 = ; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { say "enter new lang: "; $prompt2 = ; chomp $prompt2; $zu = $prompt2; } return $zu; } 1; # End of translate