yandex_translate 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -14
- data/example.rb +15 -10
- data/lib/client.rb +18 -21
- data/lib/yandex_translate/version.rb +1 -1
- data/spec/yandex_translate_spec.rb +4 -1
- data/yandex_translate.gemspec +3 -3
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 783554f753e8316a9c6b46db42b62c81dd229bcd
|
4
|
+
data.tar.gz: 2a4c87683dab36415ece46199631856c01f73748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97ed41b3eb72a042811f39a8191aec5285c59043dffe5442ecb22810284094ee9f5a6c6bd02b0ab6cc5b83ace0eb9a77528c162f4cc37da2e7908ea9a29ae780
|
7
|
+
data.tar.gz: e3aa5bfa987c0cd2341cc2e77bee2548372b9103759a011db635a20752f900984e8f016a09c2cdde4e58b1dedbac585373266aa4b178025ac12ba45211737f16
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# YandexTranslate
|
2
2
|
|
3
|
-
|
3
|
+
Library for Yandex Translate API | Библиотека для API Яндекс.Переводчика
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
|
9
|
+
|
10
10
|
gem 'yandex_translate'
|
11
|
-
|
11
|
+
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
@@ -19,24 +19,46 @@ Or install it yourself as:
|
|
19
19
|
$ gem install yandex_translate
|
20
20
|
|
21
21
|
## Usage
|
22
|
+
|
22
23
|
Api Key see on https://tech.yandex.com/translate/
|
23
24
|
|
24
|
-
|
25
|
+
```ruby
|
26
|
+
yandex = YandexTranslate::Client.new(Api_Key)
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
list of translation directions (English default)
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
yandex.get_langs
|
34
|
+
or
|
35
|
+
yandex.get_langs("en")
|
36
|
+
```
|
37
|
+
|
25
38
|
|
26
39
|
Language detection
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
yandex.detect 'Hello'
|
43
|
+
```
|
31
44
|
|
32
45
|
Language translate
|
33
|
-
# Only discovered language
|
34
|
-
puts yandex.translate("Привет")
|
35
|
-
puts yandex.last_translate
|
36
46
|
|
37
|
-
|
38
|
-
|
39
|
-
|
47
|
+
```ruby
|
48
|
+
# auto detect language
|
49
|
+
yandex.translate 'Hello', 'fr'
|
50
|
+
# with the direction of translation
|
51
|
+
yandex.translate 'Hello', 'en-fr'
|
52
|
+
# with the direction of translation and text format
|
53
|
+
yandex.translate 'Hello', 'en-fr', 'plain'
|
54
|
+
|
55
|
+
# auto detect language
|
56
|
+
yandex.translate_from_hash 'Hello', to: 'fr'
|
57
|
+
# with the direction of translation
|
58
|
+
yandex.translate_from_hash 'Hello', from: 'en', to: 'fr'
|
59
|
+
# with the direction of translation and text format
|
60
|
+
yandex.translate_from_hash 'Hello', from: 'en', to: 'fr', format: 'plain'
|
61
|
+
```
|
40
62
|
|
41
63
|
## Contributing
|
42
64
|
|
data/example.rb
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
require_relative 'lib/yandex_translate.rb'
|
2
2
|
|
3
3
|
# Need Yandex Key
|
4
|
-
key =
|
4
|
+
key = ''
|
5
5
|
|
6
6
|
yandex = YandexTranslate::Client.new(key)
|
7
7
|
|
8
|
-
puts "\nLanguage detection - \
|
8
|
+
puts "\nLanguage detection - \'Car\'\n"
|
9
9
|
# Only translate
|
10
|
-
puts yandex.detect
|
11
|
-
|
12
|
-
puts
|
10
|
+
puts yandex.detect 'car'
|
11
|
+
|
12
|
+
puts "\nLanguage translate - Car"
|
13
|
+
# Only translate language
|
14
|
+
puts yandex.translate 'Car', 'fr'
|
15
|
+
puts yandex.translate 'Car', 'en-fr'
|
16
|
+
puts yandex.translate 'Car', 'fr', 'plain'
|
17
|
+
puts "\n"
|
18
|
+
puts yandex.translate_from_hash 'Car', to: 'fr'
|
19
|
+
puts yandex.translate_from_hash 'Car', from: 'en', to: 'fr'
|
20
|
+
puts yandex.translate_from_hash 'Car', from: 'en', to: 'fr', format: 'plain'
|
13
21
|
|
14
|
-
puts "\nLanguage translate - Я перевожу слово - Привет"
|
15
|
-
# Only discovered language
|
16
|
-
puts yandex.translate("Привет")
|
17
|
-
puts yandex.last_translate
|
18
22
|
|
19
23
|
puts "\nAll Language"
|
20
|
-
yandex.get_langs_update("en")
|
21
24
|
puts yandex.get_langs
|
25
|
+
puts "\n"
|
26
|
+
puts yandex.get_langs 'en'
|
data/lib/client.rb
CHANGED
@@ -2,38 +2,35 @@ module YandexTranslate
|
|
2
2
|
class Client
|
3
3
|
def initialize(key)
|
4
4
|
@connect = Connect.new(key)
|
5
|
-
@langs = get_langs_update
|
6
|
-
@last_detect
|
7
|
-
@last_translate
|
8
5
|
end
|
9
6
|
|
10
|
-
def
|
11
|
-
@last_detect
|
12
|
-
end
|
13
|
-
|
14
|
-
def last_translate
|
15
|
-
@last_transtale
|
16
|
-
end
|
17
|
-
|
18
|
-
def get_langs
|
19
|
-
@langs
|
20
|
-
end
|
21
|
-
|
22
|
-
def get_langs_update(lang = 'en')
|
7
|
+
def get_langs(lang = 'en')
|
23
8
|
data = {"ui" => lang}
|
24
9
|
@langs = @connect.request('getLangs',data)
|
25
10
|
end
|
26
11
|
|
27
12
|
def detect(text)
|
28
13
|
data = {"text" => text}
|
29
|
-
|
30
|
-
return @langs["langs"][@last_detect["lang"]]
|
14
|
+
result = @connect.request('detect', data)['lang']
|
31
15
|
end
|
32
16
|
|
33
|
-
def translate(text, lang
|
17
|
+
def translate(text, lang, format = 'plain')
|
34
18
|
data = {"text" => text, "lang" => lang, "format" => format}
|
35
|
-
|
36
|
-
|
19
|
+
result = @connect.request('translate', data)['text']
|
20
|
+
result.size == 1 ? result.first : result
|
21
|
+
end
|
22
|
+
|
23
|
+
def translate_from_hash(text, *lang)
|
24
|
+
if lang.last.is_a?(Hash)
|
25
|
+
lang_options = lang.last
|
26
|
+
format = lang_options.key?(:format) ? lang_options[:format] : 'plain'
|
27
|
+
lang = [lang_options[:from], lang_options[:to]].compact
|
28
|
+
end
|
29
|
+
|
30
|
+
data = {"text" => text, "lang" => lang.join('-'), "format" => format}
|
31
|
+
|
32
|
+
result = @connect.request('translate', data)['text']
|
33
|
+
result.size == 1 ? result.first : result
|
37
34
|
end
|
38
35
|
end
|
39
36
|
end
|
@@ -10,6 +10,9 @@ describe 'YandexTranslate' do
|
|
10
10
|
YandexTranslate::Client.new(key).get_langs.values_at("dirs").should_not include(nil)
|
11
11
|
end
|
12
12
|
it 'translate' do
|
13
|
-
YandexTranslate::Client.new(key).translate("Привет").should_not include(nil)
|
13
|
+
YandexTranslate::Client.new(key).translate("Привет", 'en').should_not include(nil)
|
14
|
+
end
|
15
|
+
it 'translate' do
|
16
|
+
YandexTranslate::Client.new(key).translate_from_hash('Car', to: 'fr').should_not include(nil)
|
14
17
|
end
|
15
18
|
end
|
data/yandex_translate.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = YandexTranslate::VERSION
|
9
9
|
spec.authors = ["Makvik"]
|
10
10
|
spec.email = ["storm.gman@mail.ru"]
|
11
|
-
spec.summary = ""
|
12
|
-
spec.description = ""
|
13
|
-
spec.homepage = ""
|
11
|
+
spec.summary = "Library for Yandex Translate API | Библиотека для API Яндекс.Переводчика"
|
12
|
+
spec.description = "Library for Yandex Translate API | Библиотека для API Яндекс.Переводчика"
|
13
|
+
spec.homepage = "https://github.com/Makvik/yandex_translate"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex_translate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makvik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description:
|
41
|
+
description: Library for Yandex Translate API | Библиотека для API Яндекс.Переводчика
|
42
42
|
email:
|
43
43
|
- storm.gman@mail.ru
|
44
44
|
executables: []
|
@@ -60,7 +60,7 @@ files:
|
|
60
60
|
- lib/yandex_translate/version.rb
|
61
61
|
- spec/yandex_translate_spec.rb
|
62
62
|
- yandex_translate.gemspec
|
63
|
-
homepage:
|
63
|
+
homepage: https://github.com/Makvik/yandex_translate
|
64
64
|
licenses:
|
65
65
|
- MIT
|
66
66
|
metadata: {}
|
@@ -80,9 +80,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.6.8
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
|
-
summary:
|
86
|
+
summary: Library for Yandex Translate API | Библиотека для API Яндекс.Переводчика
|
87
87
|
test_files:
|
88
88
|
- spec/yandex_translate_spec.rb
|