MetaTrans
view release on metacpan or search on metacpan
bin/metatrans view on Meta::CPAN
foreach my $translator ($MetaTrans->get_translators)
{
$dicts_t->Label(
-text => $translator->host_server,
-anchor => 'w',
-bg => 'white',
-font => $nonbold_font,
)->grid(-column => 0, -row => $row, -sticky => 'wens');
$Status_Labels{$translator} = $dicts_t->Label(
-text => 'busy',
-font => $nonbold_font,
)->grid(-column => 2, -row => $row, -sticky => 'wens');
my $cb = $dicts_t->Checkbutton(
-bg => 'white',
-command => sub {
$MetaTrans->toggle_enabled_translator($translator);
&populate_from_be;
&populate_to_be;
&refresh_trans_states;
bin/metatrans view on Meta::CPAN
$Stop = 0;
my $src_lang_code = get_code_by_lang($Src_Language);
my $dest_lang_code = get_code_by_lang($Dest_Language);
my @available_trans = $MetaTrans->get_translators_for_direction(
$dest_lang_code, $src_lang_code);
foreach my $translator (@available_trans)
{
my $label = $Status_Labels{$translator};
$label->configure(-text => 'busy', -bg => 'LightSkyBlue2');
$label->update;
}
$result_t->delete('1.0', 'end');
$result_t->update;
my @translations;
$MetaTrans->run_translators($Expression, $src_lang_code, $dest_lang_code,
tk_safe => 1) or return;
bin/metatrans view on Meta::CPAN
{
do
{
$stop_b->update;
if ($Stop)
{
$MetaTrans->stop_translators;
foreach my $translator (@available_trans)
{
my $label = $Status_Labels{$translator};
if ($MetaTrans->get_translators_state($translator) eq 'busy')
{
$label->configure(-text => 'interrupted', -bg => 'red');
$label->update;
}
}
last OUTER;
}
}
until $MetaTrans->is_translation_available(0.01);
lib/MetaTrans.pm view on Meta::CPAN
return ${$self->{enabled}}{$trans};
}
=item $mt->get_translators_state($trans)
Returns current state of the translator. Possible values are
VALUE MEANING
--------- --------------------------------------------------------
"ok" successfully finished a translation (initial state, too)
"busy" working on a translation
"timeout" a timeout occured when querying an online translator
"error" unknown error occured when queryign an online translator
=cut
sub get_translators_state
{
my $self = shift;
my $trans = shift;
lib/MetaTrans.pm view on Meta::CPAN
=item $mt->run_translators($expression, $src_lang_code, $dest_lang_code,
%options)
Perform a translation of C<$expression> from C<$src_lang_code> language to
C<$dest_lang_code> language simultaneously on all enabled translators
(plug-ins), which support this translation direction. The method returns
true value on success, false on error. Use C<get_translation> method for
retrieving the results of particular translations.
The method sets the state of all plug-ins to C<"busy">. See C<get_state>
method.
There are two ways of performing parallel run. If C<$options{tk_safe}> is
undefined or set to false value, then a child process is forked for every
translator to be used and C<translate> method is called. This is generally
cleaner and more effective way of doing so then the one mentioned bellow.
However, this causes trouble if the module is used in Perl/Tk applications.
If C<$options{tk_safe}> is set to a true value, then a brand new child
process is created for every plug-in to be used. For this plug-ins are
lib/MetaTrans.pm view on Meta::CPAN
$pid = open($fhs[$i], '-|');
unless (defined $pid)
{
warn "cannot fork: $!, still trying...";
sleep 2;
}
}
until defined $pid;
}
${$self->{state}}{$translator} = "busy";
if ($pid)
{
# parent
push @{$self->{pids}}, $pid;
$self->{select}->add($fhs[$i]);
$self->{running}++;
}
else
{
lib/MetaTrans.pm view on Meta::CPAN
return 1
if @handles = 0;
my @ready = $self->{select}->can_read($timeout);
return (@ready > 0);
}
=item $mt->stop_translators
Stop all running plug-ins. This simply kills all running child processes.
The correspondent translators will end in the C<"busy"> state.
=cut
sub stop_translators
{
my $self = shift;
kill(9, @{$self->{pids}});
foreach my $fh ($self->{select}->handles)
{ $fh->close; }
( run in 0.328 second using v1.01-cache-2.11-cpan-87723dcf8b7 )