NAME

Locale::Utils::Autotranslator - Base class to translate automaticly

$Id: Autotranslator.pm 534 2014-10-27 06:46:01Z steffenw $

$HeadURL: $

VERSION

0.002

SYNOPSIS

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',
);

DESCRIPTION

Base class to translate automaticly.

SUBROUTINES/METHODS

method developer_language

Set/get the language of all msgid's. The default is 'en';

method language

Set/get the language you want to translate.

limit

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{}.

method sleep_seconds

To prevent an attack to the translation service you can sleep after each translation request. Set/get the seconds here.

method debug_code

Set/get a code reference to see what text is sent to the translation service and what you get back.

See Synopsis for parameters.

method error

Get back the error message if method translate_text dies.

method translate

$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.

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.

EXAMPLE

Inside of this distribution is a directory named example. Run the *.pl files.

DIAGNOSTICS

none

CONFIGURATION AND ENVIRONMENT

none

DEPENDENCIES

Carp

Encode

List::MoreUtils

Locale::PO

Locale::TextDomain::OO::Util::ExtractHeader

Moo

MooX::StrictConstructor

MooX::Types::MooseLike::Base

MooX::Types::MooseLike::Numeric

Try::Tiny

namespace::autoclean

INCOMPATIBILITIES

not known

BUGS AND LIMITATIONS

not known

SEE ALSO

http://en.wikipedia.org/wiki/Gettext

Locale::TextDomain::OO

AUTHOR

Steffen Winkler

LICENSE AND COPYRIGHT

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.