No commit activity in last 3 years
No release in over 3 years
Gem for sending words for translation to Yandex Translator API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.14
~> 10.0
~> 0.49.1

Runtime

~> 0.15
 Project Readme

Yandex Translator API

Text translating by Yandex Translator API

Installation

Add this line to your application's Gemfile:

gem 'yandex-translator-api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install yandex-translator-api

Usage

Create Translator object.

  require 'yandex'
  translator = Yandex::Translator.new(api_key: 'api_key')

Langs

Request for getting possible translation directions is #langs.

  translator.langs
It returns array of possible translations or error.

Responces

  {
    "dirs"=>[
      "az-ru",
      "be-bg",
      "en-ru"
    ]
  }

Detect

Request for detecting language of the text is #detect.

  translator.detect text: 'Hello', hint: 'en,de'
It returns locale of the text or error.
text - text for detecting, required param
hint - list of possible languages

Responces

  {
    "code"=>200,
    "lang"=>"en"
  }
  {
    :error=>"Bad Request"
  } 

Translate

Request for translating of the text is #translate.

  translator.translate text: 'Hello', from: 'en', to: 'ru'
It returns translated text or error.
text - text for detecting, required param
from - language of the text
to - translating direction, required param

Responces

  {
    "code"=>200,
    "lang"=>"en-ru",
    "text"=>["привет"]
  }
  {
    :error=>"Bad Request"
  } 

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kortirso/yandex-translator-api.

License

The gem is available as open source under the terms of the MIT License.