MetaTrans
view release on metacpan or search on metacpan
bin/metatrans view on Meta::CPAN
Examples:
'Dog' matches 'dog bite' (incasesensitive)
'Hund' matches 'Hund is los'
'Hund' does not match 'bissiger Hund' ('Hund' is not a prefix)
EOF
$help_text->insert('end', "\nMatch expression anywhere\n", 'underline');
$help_text->insert('end', <<EOF);
Matches those expressions which contain the searched expression, no matter
where.
Examples:
'Big Dog' matches 'very big dog'
'big dog' does not match 'big angry dog' ('big dog' is not a substring)
EOF
$help_text->insert('end', "\nMatch expression words\n", 'underline');
$help_text->insert('end', <<EOF);
Matches those expressions which contain all the words of the searched
expression.
Examples:
'big dog' matches 'big angry dog'
'big dog' does not match 'angry dog' (not all words are contained)
EOF
$help_text->insert('end', "\nNo filtering\n", 'underline');
$help_text->insert('end', <<EOF);
Just no filtering at all :).
EOF
$help_text->insert('end', "\nMatch at word boundaries only\n", 'underline');
$help_text->insert('end', <<EOF);
This options makes matching behave in a slightly different way.
Subexpressions and words are matched at word boundaries only. In practice
this means that with 'Match expression words' the expression 'big dog'
won't be matched to 'big angry doggie' while it would be with
match-at-word-boundaries-only option disabled. The same applies to
'Match expression at start' and 'Match expression anywhere'. The option
has no effect with 'Exact match' and 'No filtering'.
EOF
}
################################################################################
# gui initialization #
################################################################################
&populate_from_be;
&populate_to_be;
&enable_disable_swap;
my %Status_Labels;
my $row = 1;
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;
},
)->grid(-column => 4, -row => $row, -sticky => 'we');
$cb->select unless $MetaTrans->is_enabled_translator($translator);
$row ++;
$dicts_t->Frame(
-width => 1,
-height => 1,
-bg => 'black',
)->grid(-column => 0, -row => $row, -columnspan => 5);
$row ++;
}
&refresh_trans_states;
################################################################################
# procedures #
################################################################################
sub populate_from_be
{
$from_be->delete(0, 'end');
my @src_lang_codes = $MetaTrans->get_all_src_lang_codes;
my %src_lang_codes_hash = map {($_, 1)} @src_lang_codes;
foreach my $lang_code (@src_lang_codes)
{ $from_be->insert('end', get_lang_by_code($lang_code)); }
unless (defined $Src_Language &&
$src_lang_codes_hash{get_code_by_lang($Src_Language)})
{
if ($config{lang_from} && $src_lang_codes_hash{$config{lang_from}})
{
$Src_Language = get_lang_by_code($config{lang_from});
}
elsif ($src_lang_codes[0])
{
$Src_Language = get_lang_by_code($src_lang_codes[0]);
}
}
}
sub populate_to_be
{
$to_be->delete(0, 'end');
$Old_Dest_Language = $config{lang_to}
bin/metatrans view on Meta::CPAN
{
my $src_lang_code = get_code_by_lang($Src_Language);
my $dest_lang_code = get_code_by_lang($Dest_Language);
@available_trans = $MetaTrans->get_translators_for_direction(
$dest_lang_code, $src_lang_code);
}
my %available_trans_hash;
foreach my $translator (@available_trans)
{ $available_trans_hash{$translator} = 1; }
my $ready_count = 0;
foreach my $translator ($MetaTrans->get_translators)
{
my $label = $Status_Labels{$translator};
unless ($MetaTrans->is_enabled_translator($translator))
{
$label->configure(-text => 'disabled', -bg => 'gray');
next;
}
if ($available_trans_hash{$translator})
{
$label->configure(-text => 'ready', -bg => 'green');
$ready_count++;
}
else
{
$label->configure(-text => 'N/A', -bg => 'gray');
}
}
$trans_b->configure(-state => $ready_count > 0 ? 'normal' : 'disabled');
}
sub run_translation
{
$Expression =~ s/\s+/ /g;
$Expression =~ s/^ //;
$Expression =~ s/ $//;
$expr_e->selectionRange(0, 'end');
if ($Expression eq '')
{
&error_dialog('No expression to be translated specified.');
return;
}
$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;
OUTER: while (1)
{
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);
my ($translation, $translator) = $MetaTrans->get_translation(
return_translators => 1);
last unless defined $translator;
if ($translation eq '')
{
my $label = $Status_Labels{$translator};
$label->configure(
-text => $MetaTrans->get_translators_state($translator),
-bg => $MetaTrans->get_translators_state($translator) eq 'ok' ?
'green' : 'red',
);
$label->update;
&show_translations(MetaTrans::sort_translations(
$Expression, @translations));
next;
}
push @translations, $translation;
}
}
sub show_translations
{
my @translations = @_;
my $max_characters = ($result_t->width - 31) / $result_t->fontMeasure(
$unicode_font, '0');
my $max_eq_sign_pos = 0;
foreach my $trans (@translations)
{
$trans = Encode::decode_utf8($trans)
unless Encode::is_utf8($trans);
my $eq_sign_pos = index($trans, '=');
$max_eq_sign_pos = $eq_sign_pos
if $eq_sign_pos > $max_eq_sign_pos;
}
$max_eq_sign_pos = $max_characters / 2
if $max_eq_sign_pos > $max_characters / 2;
$result_t->delete('1.0', 'end');
my $bg = @translations % 2 == 1 ? 'dark' : 'light';
my $i = 1;
foreach my $trans (@translations)
{
my $eq_sign_pos = index($trans, '=');
$eq_sign_pos = $max_eq_sign_pos
( run in 2.040 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )