1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-10-22 20:41:26 +00:00

- Add translator 0.1.0, a GTK+ frontend to the Babelfish translation service.

PR:		ports/73063
Submitted by:	Jean-Yves Lefort <jylefort@brutele.be>
Approved by:	pav (mentor)
This commit is contained in:
Florent Thoumie 2005-03-09 16:01:13 +00:00
parent 3430b5984c
commit 6dc74323ad
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=130733
6 changed files with 250 additions and 0 deletions

View File

@ -401,6 +401,7 @@
SUBDIR += tkrunit
SUBDIR += tpp
SUBDIR += translate
SUBDIR += translator
SUBDIR += ttyrec
SUBDIR += tvguide
SUBDIR += txt2regex

47
misc/translator/Makefile Normal file
View File

@ -0,0 +1,47 @@
# New ports collection makefile for: translator
# Date created: 24 Oct 2004
# Whom: Jean-Yves Lefort <jylefort@brutele.be>
#
# $FreeBSD$
#
PORTNAME= translator
PORTVERSION= 0.1.0
CATEGORIES= misc
MASTER_SITES= http://jodrell.net/files/translator/
MAINTAINER= jylefort@brutele.be
COMMENT= A GTK+ frontend to the Babelfish translation service
RUN_DEPENDS= ${SITE_PERL}/${PERL_ARCH}/Gtk2.pm:${PORTSDIR}/x11-toolkits/p5-Gtk2 \
${SITE_PERL}/${PERL_ARCH}/Gtk2/GladeXML.pm:${PORTSDIR}/x11-toolkits/p5-Glade2 \
${SITE_PERL}/${PERL_ARCH}/Gnome2/GConf.pm:${PORTSDIR}/devel/p5-Gnome2-GConf \
${SITE_PERL}/WWW/Babelfish.pm:${PORTSDIR}/www/p5-WWW-Babelfish
USE_X_PREFIX= yes
USE_PERL5= yes
NO_BUILD= yes
.include <bsd.port.pre.mk>
HAVE_THREADS!= ${PERL} -mthreads -e '' >/dev/null 2>&1 && ${ECHO} 'yes' || true
.if ${PERL_LEVEL} < 500800 || empty(HAVE_THREADS)
IGNORE= "Needs threaded perl 5.8.0 or higher, install lang/perl5.8 with threads support and try again"
.endif
post-patch:
@${SED} -e \
's|share/pixmaps|share/gnome/pixmaps| ; \
s|@PREFIX@|${PREFIX}|' \
${WRKSRC}/translator.pl > ${WRKSRC}/translator
do-install:
${MKDIR} ${PREFIX}/bin
${INSTALL_SCRIPT} ${WRKSRC}/translator ${PREFIX}/bin
${MKDIR} ${PREFIX}/share/gnome/pixmaps
${INSTALL_DATA} ${WRKSRC}/translator.png ${PREFIX}/share/gnome/pixmaps
${MKDIR} ${PREFIX}/share/translator
${INSTALL_DATA} ${WRKSRC}/translator.glade ${PREFIX}/share/translator
.include <bsd.port.post.mk>

2
misc/translator/distinfo Normal file
View File

@ -0,0 +1,2 @@
MD5 (translator-0.1.0.tar.gz) = abaae4506a2ea366b35423289034eeaf
SIZE (translator-0.1.0.tar.gz) = 17214

View File

@ -0,0 +1,187 @@
$FreeBSD$
--- translator.pl.orig
+++ translator.pl
@@ -2,20 +2,19 @@
# nifty front-end to Altavista's Babel Fish.
# $Id: translator.pl,v 1.13 2003/12/19 11:50:02 jodrell Exp $
use WWW::Babelfish;
-use IO::Scalar;
use threads;
use threads::shared;
+use Thread::Queue;
use File::Basename qw(basename);
-use Data::Dumper;
use strict;
#
# these are shared between the main thread and the worker:
#
-my @queue : shared;
+my $input_queue = new Thread::Queue;
+my $output_queue = new Thread::Queue;
+
my @errors : shared;
-my $finished : shared;
-my $output : shared;
my $source : shared;
my $dest : shared;
my $running : shared;
@@ -30,9 +29,6 @@
#
# set up the application:
#
-$finished = 0;
-$pending = 0;
-
my $NAME = 'Translator';
my $VERSION = '0.1.0';
my $RCFILE = sprintf('%s/.%src', $ENV{HOME}, lc($NAME));
@@ -80,24 +76,25 @@
# places output into the $output array, and we need to keep the entry up to date:
#
Glib::Timeout->add(50, sub {
- if ($pending == 1) {
- $app->get_widget('output')->get_buffer->set_text($output) ;
- $pending = 0;
+ if (defined(my $output = $output_queue->dequeue_nb)) {
+ $app->get_widget('output')->get_buffer->set_text($output);
}
- if ($running == 1) {
- $app->get_widget('main_window')->get_root_window->set_cursor($busy);
- $app->get_widget('translate_button')->set_sensitive(0);
- $app->get_widget('input')->set_editable(0);
- } else {
- $app->get_widget('main_window')->get_root_window->set_cursor($normal);
- $app->get_widget('translate_button')->set_sensitive(1);
- $app->get_widget('input')->set_editable(1);
+
+ {
+ lock($running);
+ $app->get_widget('main_window')->get_root_window->set_cursor($running ? $busy: $normal);
+ $app->get_widget('translate_button')->set_sensitive(! $running);
+ $app->get_widget('input')->set_editable(! $running);
}
- if (scalar(@errors) > 0) {
- my $error_dialog = Gtk2::MessageDialog->new($app->get_widget('main_window'), 'modal', 'error', 'ok', shift(@errors));
- $error_dialog->set_icon($app->get_widget('main_window')->get_icon);
- $error_dialog->signal_connect('response', sub { $error_dialog->destroy });
- $error_dialog->show_all;
+
+ {
+ lock(@errors);
+ if (scalar(@errors) > 0) {
+ my $error_dialog = Gtk2::MessageDialog->new($app->get_widget('main_window'), 'modal', 'error', 'ok', shift(@errors));
+ $error_dialog->set_icon($app->get_widget('main_window')->get_icon);
+ $error_dialog->signal_connect('response', sub { $error_dialog->destroy });
+ $error_dialog->show_all;
+ }
}
return 1;
});
@@ -107,46 +104,60 @@
Gtk2->main;
sub worker {
- my $fish = WWW::Babelfish->new;
+ my $fish = WWW::Babelfish->new(agent => 'Mozilla/8.0');
$fish->{ua}->timeout(10);
- while ($finished == 0) {
- if (scalar(@queue) > 0) {
+ while (my $input = $input_queue->dequeue) {
+ my $output = '';
+ {
+ lock($running);
$running = 1;
- $output = '';
- my $input = shift(@queue);
- my $fh = IO::Scalar->new(\$output);
+ }
+ open my $fh, ">", \$output or die;
+ {
+ lock($proxy);
if ($proxy ne '') {
$fish->{proxy} = $proxy;
$fish->{ua}->proxy('http', 'http://'.$proxy.'/');
}
+ }
+ {
+ lock($source);
+ lock($dest);
if (!$fish->translate(
source => $source,
destination => $dest,
ofh => $fh,
text => $input,
)) {
+ lock(@errors);
push(@errors, "Error: $!");
}
- $pending = 1;
- } else {
+ }
+ {
+ lock($running);
$running = 0;
- threads->yield;
}
+ $output_queue->enqueue($output);
}
- return 1;
}
sub close_program {
save_options();
- $finished = 1;
+ $input_queue->enqueue(undef); # terminate the worker thread
Gtk2->main_quit;
$worker->join;
exit;
}
sub translate {
- $source = $app->get_widget('from_combo')->entry->get_text;
- $dest = $app->get_widget('to_combo')->entry->get_text;
+ {
+ lock($source);
+ $source = $app->get_widget('from_combo')->entry->get_text;
+ }
+ {
+ lock($dest);
+ $dest = $app->get_widget('to_combo')->entry->get_text;
+ }
my $input = $app->get_widget('input')->get_buffer->get_text(
$app->get_widget('input')->get_buffer->get_start_iter,
$app->get_widget('input')->get_buffer->get_end_iter,
@@ -159,9 +170,12 @@
} else {
$message = 'Please enter some text to translate.';
}
- push(@errors, $message);
+ {
+ lock(@errors);
+ push(@errors, $message);
+ }
} else {
- push(@queue, $input);
+ $input_queue->enqueue($input);
}
return 1;
}
@@ -284,6 +298,7 @@
}
sub source_changed {
+ lock($source);
$source = $app->get_widget('from_combo')->entry->get_text;
return undef if ($source eq '');
$app->get_widget('to_combo')->set_popdown_strings(sort(keys(%{$pairs->{$source}})));
@@ -292,6 +307,7 @@
sub set_proxy {
if ($client->get_bool($use_proxy_key) == 1) {
+ lock($proxy);
$proxy = sprintf(
'%s:%d',
$client->get_string($proxy_host),

View File

@ -0,0 +1,9 @@
Translator is a simple front-end to AltaVista's excellent
Babelfish. It is designed to integrate into the GNOME desktop, and as
such features an (almost) HIG compliant interface, and support for
GNOME's HTTP proxy settings.
WWW: http://jodrell.net/projects/translator/
- Jean-Yves Lefort
jylefort@brutele.be

View File

@ -0,0 +1,4 @@
bin/translator
share/gnome/pixmaps/translator.png
%%DATADIR%%/translator.glade
@dirrm %%DATADIR%%