-
-
24 Feb 2017 13:16:28 UTC
- Distribution: Locale-Utils-Autotranslator
- Module version: 1.001
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (0)
- Testers (139 / 172 / 0)
- Kwalitee
Bus factor: 1- 23.77% Coverage
- License: perl_5
- Perl: v5.8.0
- Activity
24 month- Tools
- Download (16.45KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
++ed by:1 non-PAUSE userand 1 contributors- Steffen Winkler <steffenw at cpan.org>
- Dependencies
- Carp
- Encode
- HTML::Entities
- HTTP::Request::Common
- JSON
- LWP::UserAgent
- Locale::PO
- Locale::TextDomain::OO::Util
- Locale::TextDomain::OO::Util::ExtractHeader
- Moo
- MooX::StrictConstructor
- MooX::Types::MooseLike
- MooX::Types::MooseLike::Base
- Try::Tiny
- URI
- namespace::autoclean
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
- NAME
- VERSION
- SYNOPSIS
- DESCRIPTION
- SUBROUTINES/METHODS
- EXAMPLE
- DIAGNOSTICS
- CONFIGURATION AND ENVIRONMENT
- DEPENDENCIES
- INCOMPATIBILITIES
- BUGS AND LIMITATIONS
- SEE ALSO
- AUTHOR
- LICENSE AND COPYRIGHT
NAME
Locale::Utils::Autotranslator - Base class to translate automaticly
$Id: Autotranslator.pm 614 2015-08-17 10:28:48Z steffenw $
$HeadURL: $
VERSION
1.001
SYNOPSIS
package MyAutotranslator; use Moo; extends qw( Locale::Utils::Autotranslator ); sub translate_text { my ( $self, $text ) = @_; my $translation = MyTranslatorApi ->new( from => $self->developer_language, to => $self->language, ) ->translate($text); return $translation; }
How to use see Locale::Utils::Autotranslator::ApiMymemoryTranslatedNet.
my $obj = MyAutotranslator->new( language => 'de', # all following parameters are optional developer_language => 'en', # en is the default before_translation_code => sub { my ( $self, $msgid ) = @_; ... return 1; # true: translate, false: skip translation }, after_translation_code => sub { my ( $self, $msgid, $msgstr ) = @_; ... return 1; # true: translate, false: skip translation }, ); $identical_obj = $obj->translate( 'mydir/de.pot', 'mydir/de.po', ); my $translation_count = $obj->translation_count;
Return code of E.g. you have a limit of 100 free translations or 10000 words for 1 day you can skip further translations by return any false.
Use that methods for debugging output.
DESCRIPTION
Base class to translate automaticly.
SUBROUTINES/METHODS
method developer_language
Get back the language of all msgid's. The default is 'en';
method language
Get back the language you want to translate.
before_translation_code, after_translation_code
Get back the code references:
$code_ref = $obj->before_translation_code; $code_ref = $obj->after_translation_code;
method translate
$obj->translate('dir/de.pot', 'dir/de.po');
That means: Read the de.pot file (also possible *.po). Translate the missing stuff. Write back to de.po file.
method translate_text
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.
method comment
Set a typical comment to mark the translation as translated by ... in API class. Get back that comment.
E.g.
$self->comment('translated by: api.mymemory.translated.net');
method translation_count
Get back the count of translations. This is not the count of translated messages, this is the count of successful translate_text calls.
my $translation_count = $obj->translation_count;
method error
Get back the error message if method translate_text dies.
EXAMPLE
Inside of this distribution is a directory named example. Run the *.pl files.
DIAGNOSTICS
none
CONFIGURATION AND ENVIRONMENT
none
DEPENDENCIES
Locale::TextDomain::OO::Util::ExtractHeader
MooX::Types::MooseLike::Numeric
INCOMPATIBILITIES
not known
BUGS AND LIMITATIONS
not known
SEE ALSO
http://en.wikipedia.org/wiki/Gettext
AUTHOR
Steffen Winkler
LICENSE AND COPYRIGHT
Copyright (c) 2014 - 2015, 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.
Module Install Instructions
To install Locale::Utils::Autotranslator, copy and paste the appropriate command in to your terminal.
cpanm Locale::Utils::Autotranslator
perl -MCPAN -e shell install Locale::Utils::Autotranslator
For more information on module installation, please visit the detailed CPAN module installation guide.