0.0
No commit activity in last 3 years
No release in over 3 years
Ruby gem Yandex API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0
 Project Readme

Ruby gem - TranslatorAPI

Library Ruby the translator based on Yandex API.

You need to get a key to use translator

Usage

You create an instance of the class Translator::Text to be transferred to the method #new key and language of the translation. The default language of translation Russian.

You can use ready-made gem installing them with rubygems

gem install TranslatorAPI

After require you can use gem

require 'translator_api'
translator = TranslatorAPI::Translator.new("your key","en") 

If your key or reduction of language is wrong it will return nil.

Translator::Translator.new("invalid key","en") # => nil

Method #get_list

Call the method #get_list for determining the list of supported languages and translation directions.

langs, dirs = translator.get_list

langs, dirs = Translator.get_list_language 
langs.each { |key, lang| puts "#{key} : #{lang}" } # => af : Африкаанс 
                                                   # => ar : Арабский
                                                   # [list of reduction and language](https://tech.yandex.ru/translate/doc/dg/concepts/langs-docpage/) 

dirs.each { |directions| puts directions} # => az-ru
                                          # => be-bg
                                          # => ... list of translation directions

Method #detect

Call the method #detect for the determination of language of a text.

translator.detect "Something text" # => English

Returns the value of a language depends on the reduction in the the transmitted method #new.

TranslatorAPI::Translator.new("your key","zh").detect "Something text" # => 英語 ("zh" - Chinese)

If the language is not supported it will return nil.

translator.detect "language is not supported" # => nil

Method #translate

Call the method #translate to translate text. The final language of the translation is determined by the reduction method #new. Text can not contain more than 10,000 characters else it will return nil.

translator.translate "一些文本" # => "Some of the text"

If the language is not supported it will return the original text.

translator.translate "भाषा" # => "भाषा"

You can manually set the translation direction. Language is supported or not is supported and direction is wrong but exist it will return the original text.

translator.translate("text","zh-af") # => "text"

Language is supported or not is supported and direction is not exist it will return nil.

translator.translate("text","direction is not exist") # => nil

Good luck in the use the Translator