Module: Y::Translate
- Defined in:
- lib/y/translate.rb,
lib/y/translate/api.rb,
lib/y/translate/error.rb,
lib/y/translate/version.rb,
lib/y/translate/configuration.rb
Defined Under Namespace
Classes: API, Configuration, Error
Constant Summary
collapse
- VERSION =
"0.2.2"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
11
12
13
|
# File 'lib/y/translate.rb', line 11
def self.configuration
@configuration ||= Configuration.new
end
|
Class Method Details
15
16
17
18
|
# File 'lib/y/translate.rb', line 15
def self.configure
yield(configuration)
API.key = configuration.api_key
end
|
.detect(text) ⇒ Object
42
43
44
|
# File 'lib/y/translate.rb', line 42
def self.detect(text)
request(API::METHOD_DETECT, text: text)['lang']
end
|
.get_langs ⇒ Object
28
29
30
31
32
33
|
# File 'lib/y/translate.rb', line 28
def self.get_langs
request(
API::METHOD_GET_LANGS,
ui: configuration.lang_to
)['dirs']
end
|
.get_langs_names ⇒ Object
35
36
37
38
39
40
|
# File 'lib/y/translate.rb', line 35
def self.get_langs_names
request(
API::METHOD_GET_LANGS,
ui: configuration.lang_to
)['langs']
end
|
.reset_default ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/y/translate.rb', line 20
def self.reset_default
api_key = configuration.api_key
@configuration = Configuration.new
configure do |config|
config.api_key = api_key
end
end
|
.translate(text, params = {}) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/y/translate.rb', line 46
def self.translate(text, params = {})
params[:text] = text
params[:lang] = configuration.lang_to unless params.key?(:lang)
response = request(API::METHOD_TRANSLATE, params)['text']
response = response[0] if response.count == 1
response
end
|