
POE::Component::Lingua::Translate - A non-blocking wrapper around Lingua::Translate

use POE;
use POE::Component::Lingua::Translate;
POE::Session->create(
package_states => [
main => [ qw(_start translated) ],
],
);
$poe_kernel->run();
sub _start {
my $heap = $_[HEAP];
$heap->{trans} = POE::Component::Lingua::Translate->new(
alias => 'translator',
back_end => 'Babelfish',
src => 'en',
dest => 'de',
);
$poe_kernel->post(translator => translate => 'This is a sentence');
return;
}
sub translated {
my $result = $_[ARG0];
# prints 'Dieses ist ein Satz'
print $result . "\n";
}

POE::Component::Lingua::Translate is a POE component that provides a non-blocking wrapper around Lingua::Translate. It accepts translate events and emits translated events back.

newArguments
'alias', an optional alias for the component's session.
Any other arguments will be passed verbatim to Lingua::Translate's constructor.

session_idTakes no arguments. Returns the POE Session ID of the component.

The POE events this component will accept.
translateThe first argument should be a string containing some text to translate. The second argument (optional) can be a hash reference containing some context information. You'll get this hash reference back with the translated event.
shutdownTakes no arguments, terminates the component.

The POE events emitted by this component.
translatedARG0 is the translated text. ARG1 is the context hashref from translate. If there was an error, ARG2 will be the error string.

Hinrik Örn Sigurðsson, hinrik.sig@gmail.com

Copyright 2008 Hinrik Örn Sigurðsson
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.