Locale::Utils::Autotranslator - Base class to translate automaticly
$Id: Autotranslator.pm 534 2014-10-27 06:46:01Z steffenw $
$HeadURL: $
0.003
package MyAutotranslator;
use Moo;
extends qw( Locale::Utils::Autotranslator );
sub translate_text { my ( $self, $text ) = @_;
my $developer_language = $self->developer_language; my $language = $self->language; my $translation = MyTranslatorApi ->new( from => $developer_language, to => $language, ) ->translate($text);
return $translation; }
How to use see Locale::Utils::Autotranslator::ApiMymemoryTranslatedNet.
my $obj = MyAutotranslator->new( language => 'de', # optional debug_code => sub { my ( $language, $text ) = @_; ... }, ); $obj->translate( 'mydir/de.pot', 'mydir/de.po', );
Base class to translate automaticly.
Set/get the language of all msgid's. The default is 'en';
Set/get the language you want to translate.
E.g. you have a limit of 100 free translations in 1 day you can run that each day with that limit. After that method translate returns, maybe with left untranslated messages.
You can read back the left limit and use them on other files. It is also allowed to run method translate with limit 0 first. Then it will translate all missing stuff to q{}.
To prevent an attack to the translation service you can sleep after each translation request. Set/get the seconds here.
Set/get a code reference to see what text is sent to the translation service and what you get back.
See Synopsis for parameters.
Get back the error message if method translate_text dies.
$object->translate('dir/de.pot', 'dir/de.po');
That means: Read the de.pot file (also possible *.po). Translate the 1st missing stuff. Write back the de.po file. Look for more missing translations. Translate the next missing stuff.
Why write back so often? If something is broken (die) during translation the error is set.
In base class there is only a dummy method that returns q{}
.
The subclass has to implement that method. Check the code of Locale::Utils::Autotranslator::ApiMymemoryTranslatedNet to see how to implement.
Inside of this distribution is a directory named example. Run the *.pl files.
none
none
Locale::TextDomain::OO::Util::ExtractHeader
MooX::Types::MooseLike::Numeric
not known
not known
http://en.wikipedia.org/wiki/Gettext
Steffen Winkler
Copyright (c) 2014,
Steffen Winkler
<steffenw at cpan.org>
.
All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.