NAME

WebService::Async::Microsoft::TranslateV2 - Subclass of WebService::Async that has a simple interface to Microsoft Translate Service.

SYNOPSIS

Simple usage

SOURCE

use WebService::Async::Microsoft::TranslateV2; my $translator = WebService::Async::Microsoft::TranslateV2->new( app_id => '[YOUR BING APPLICATION ID]', ); $translator->source_language('en'); $translator->set_destination_languages(qw(it fr)); $translator->set_message( message1 => 'apple' ); $translator->set_message( message2 => 'banana' ); $translator->set_message( message3 => 'orange' ); $translator->translate( on_each_translation => sub { my ($self, $id, $res) = @; print $res; }, on_translation_complete => sub { my ($self, $all_res) = @; print $all_res; }, );

RESULTS

arancione Apple la banane banana orange mela banana la banane arancione orange mela Apple

Using custom templates

SOURCE

use WebService::Async::Microsoft::TranslateV2; my $translator = WebService::Async::Microsoft::TranslateV2->new( app_id => '[YOUR BING APPLICATION ID]', );

$translator->single_template(get_data_section('single')); $translator->whole_template(get_data_section('whole')); $translator->critical_error_template(get_data_section('critical_error'));

$translator->source_language('en'); $translator->set_destination_languages(qw(it fr)); $translator->set_message( message1 => 'apple' ); $translator->set_message( message2 => 'banana' ); $translator->set_message( message3 => 'orange' ); $translator->translate( on_each_translation => sub { my ($self, $id, $res) = @; print $res; }, on_translation_complete => sub { my ($self, $all_res) = @; print $all_res; }, );

DATA
@@ single ?= Text::MicroTemplate::encoded_string '' ? my ($id, $lang, $message) = @_ ?= "\0"

@@ whole ?= Text::MicroTemplate::encoded_string '' ? my ($self, $messages) = @_; ? for my $key ($self->all_messages_ids) { ? for my $lang ($self->all_destination_languages) { ? my $text = $self->get_translated_message(id => $key, language => $lang); ? } ? } ?= "\0"

@@ critical_error CRITICAL ERROR

RESULTS

arancione Apple la banane banana orange mela banana la banane arancione orange mela Apple

DESCRIPTION

WebService::Async::Microsoft::TranslateV2 is subclass of WebService::Async that has a simple interface to Microsoft Translate Service.

METHODS

source_language

Sets the source language.

$translator->source_language('en');

set_destination_languages

Sets destination languages.

$translator->set_destination_languages(qw(it fr));

set_message

Sets messages that you want to translate.

$translator->set_message( message1 => 'apple' );

translate

$translator->translate( on_each_translation => sub { my ($self, $id, $res) = @; }, on_translation_complete => sub { my ($self, $all_res) = @; }, );

AUTHOR

keroyon keroyon@cpan.org

SEE ALSO

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.