The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Yandex::Translate - a simple API for Yandex.Translate

VERSION

version 1.002

SYNOPSIS

    use utf8; #It is require
    use Yandex::Translate;

    my $tr = Yandex::Translate->new;

    # Set the Yandex API key that you can get from https://tech.yandex.com/
    $tr->set_key('yandex_key');

    # Set the text that you want to translate
    $tr->set_text('In the name of God');

    # Set the source language
    $tr->set_from_lang('en');

    # Set the destination language
    $tr->set_to_lang('ru');

    # Get the result
    print $tr->translate();

DESCRIPTION

Yandex.Translate (previously Yandex.Translation) is a web service provided by Yandex, intended for the translation of text or web pages into another language.

The service uses a self-learning statistical machine translation, developed by Yandex. The system constructs the dictionary of correspondences based on the analysis of millions of translated texts.

METHODS

new

    $tr = Yandex::Translate->new(@attributes);

This constructor returns a new Yandex::Translate object. Optional attributes include:

  • _key_ - An API key that you can get from the Yandex website after registering, string format.

  • _text_ - The text that you want to translate, string format.

  • _from_lang_ - The source language, string format.

  • _to_lang_ - The destination language, string format.

  • _ui_ - The user interface language, string format.

  • _hint_ - A list of comma-separated languages for detecting the text language, array reference format.

  • _format_ - The returned text format, either plain (default) or html.

  • _options_ - 1 if the response should include the automatically detected language of the text to be translated.

set_key

    $tr->set_key('yandex_key');

This method is used to pass a Yandex API key (string), instead of passing it in "new". A Yandex::Translate object can be instantiated without any attributes.

set_text

    $tr->set_text('text_to_translate');

This method is used to pass a text to translate (string).

set_from_lang

    $tr->set_from_lang('zh');

This method is used to pass a source language (string). For example, Chinese would be given as zh.

set_to_lang

    $tr->set_to_lang('ar');

This method is used to pass a destination language (string). For example, Arabic would be given as ar.

set_ui

    $tr->set_ui('fr');

This method is used to set the user interface language (string). For example, French would be given as fr.

set_default_ui

    $tr->set_default_ui('ru');

This method is used to set the default user interface language (string). Either ru (Russian) or en (English) or tr (Turkish) can be given.

set_hint

    $tr->set_hint([qw{es pt}]);

This method is used to set the list of likely languages for detecting the text language (array reference). For example, Spanish and Portuguese would be given as [qw{es pt}].

set_format

    $tr->set_format('html');

This method is used to set the format of the text to be translated (string). Either plain or html can be given.

set_options

    $tr->set_options('1');

This method is used to set options for the translated text language response (string). The only option currently supported is 1 (to also return the automatically detected language of the text to be translated).

translate

    print $tr->translate(), "\n";

This method is used to get the translated text. If "set_options" has been previously called, it returns an array of two elements, with the first element containing the detected language of the original text (string) and the second element containing the translated text (string); otherwise, only the translated text is returned.

detect_lang

    print $tr->detect_lang(), "\n";

This method is used to detect the language of the text. It returns a string.

get_langs_list

    print join(',', $tr->get_langs_list()), "\n";

    print scalar($tr->get_langs_list()), "\n";

This method is used to get the list of supported translation directions. In array context, it returns an array of these directions; in scalar context, it returns the count of them.

get_yandex_technology_reference

    print $tr->get_yandex_technology_reference(), "\n";

    print $tr->get_yandex_technology_reference({ id => 'yandex' }), "\n";

This method is used to get the HTML <a> element that the Yandex Terms of Use of API Yandex.Translate Service requires to be displayed either directly above or directly below the translated text. An optional hash reference of attributes and values for the returned element can be passed in.

SEE ALSO

For more information, please visit Yandex.

SUPPORT

Bugs / Feature Requests

Please report any bugs or feature requests on my email.

https://fossil.falseking.site/ticket

Source Code

This is open source software. The code repository is available for public review and contribution under the terms of the license.

https://fossil.falseking.site/dir?ci=tip&type=tree

AUTHORS

  • James Axl <axlrose112@gmail.com>

  • Christian Carey

COPYLEFT AND LICENSE

This software is copyleft © 2017 by James Axl.

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