easy_translate 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dc42a67dbc77615111fadfe7e35dc2ed65c72148
4
- data.tar.gz: 629842ec7b8e4dd08d5a53169e29b0f7f08e80d8
2
+ SHA256:
3
+ metadata.gz: 8ce6cc748c26435deec480aebdf4dfcdadcaf75b967907b64109095dfd4434ce
4
+ data.tar.gz: eec6a4e68be5f53f931906a05de472a8f0438c3815bd9bbc6e7e48cff525d5b0
5
5
  SHA512:
6
- metadata.gz: dfe3e38981eb1003583a65720823e8160f477ebee17fad18078b936a6e8407dfb28a6ca7a491f1f02af43b914cff8aefc2c6734f7de538b8d7f8a476f6d29fe4
7
- data.tar.gz: '0439a0871adf41762f7630f1a18ce0e110411cff3290fee0ceb76e82159d1022b1351de91c338dbe2b29afb414c09e78fc0e14b6c74f8dae8848126c4e8c0013'
6
+ metadata.gz: 39a1f3bc2af6f22fb96f0f02fa1176d4bff2330ea6ea789d63b592d08224cde1ed88611e4f8b6fc925a57441a8cccbe7ca386c099ec201a5661df04fce2c6b9d
7
+ data.tar.gz: 8aa2e23c5d7167e88b38512e580283a13a135240321599ee8a4c90267746d55a695ae12d07b6d09a7a8737a2022ab9dc477ae24a50c1905bbe779be320d08759
@@ -21,8 +21,8 @@ module EasyTranslate
21
21
  request = DetectionRequest.new(texts, options, http_options)
22
22
  raw = request.perform_raw
23
23
  detections = JSON.parse(raw)['data']['detections'].map do |res|
24
- res.empty? ? nil :
25
- options[:confidence] ?
24
+ res.empty? ? nil :
25
+ options[:confidence] ?
26
26
  { :language => res.first['language'], :confidence => res.first['confidence'] } : res.first['language']
27
27
  end
28
28
  end
@@ -56,9 +56,9 @@ module EasyTranslate
56
56
  end
57
57
 
58
58
  # The body for the request
59
- # @return [String] the body for the request, URL escaped
59
+ # @return [String] the body for the request
60
60
  def body
61
- @texts.map { |t| "q=#{CGI::escape(t)}" }.join '&'
61
+ JSON.generate({ q: @texts })
62
62
  end
63
63
 
64
64
  # Whether or not this was a request for multiple texts
@@ -3,57 +3,140 @@ module EasyTranslate
3
3
  LANGUAGES = {
4
4
  'af' => 'afrikaans',
5
5
  'sq' => 'albanian',
6
+ 'am' => 'amharic',
6
7
  'ar' => 'arabic',
8
+ 'hy' => 'armenian',
9
+ 'as' => 'assamese',
10
+ 'ay' => 'aymara',
11
+ 'az' => 'azerbaijani',
12
+ 'bm' => 'bambara',
13
+ 'eu' => 'basque',
7
14
  'be' => 'belarusian',
15
+ 'bn' => 'bengali',
16
+ 'bho' => 'bhojpuri',
17
+ 'bs' => 'bosnian',
8
18
  'bg' => 'bulgarian',
9
19
  'ca' => 'catalan',
20
+ 'ceb' => 'cebuano',
21
+ 'ny' => 'chichewa',
22
+ 'zh' => 'chinese_simplified',
10
23
  'zh-CN' => 'chinese_simplified',
11
24
  'zh-TW' => 'chinese_traditional',
25
+ 'co' => 'corsican',
12
26
  'hr' => 'croatian',
13
27
  'cs' => 'czech',
14
28
  'da' => 'danish',
29
+ 'dv' => 'divehi',
30
+ 'doi' => 'dogri',
15
31
  'nl' => 'dutch',
16
32
  'en' => 'english',
33
+ 'eo' => 'esperanto',
17
34
  'et' => 'estonian',
35
+ 'ee' => 'ewe',
18
36
  'tl' => 'filipino',
19
37
  'fi' => 'finnish',
20
38
  'fr' => 'french',
39
+ 'fy' => 'frisian',
21
40
  'gl' => 'galician',
41
+ 'lg' => 'ganda',
42
+ 'ka' => 'georgian',
22
43
  'de' => 'german',
23
44
  'el' => 'greek',
45
+ 'gn' => 'guarani',
46
+ 'gu' => 'gujarati',
47
+ 'ht' => 'haitian_creole',
48
+ 'ha' => 'hausa',
49
+ 'haw' => 'hawaiian',
50
+ 'he' => 'hebrew',
24
51
  'iw' => 'hebrew',
25
52
  'hi' => 'hindi',
53
+ 'hmn' => 'hmong',
26
54
  'hu' => 'hungarian',
27
55
  'is' => 'icelandic',
56
+ 'ig' => 'igbo',
57
+ 'ilo' => 'iloko',
28
58
  'id' => 'indonesian',
29
- 'ga' => 'irish',
59
+ 'ga' => 'irish_gaelic',
30
60
  'it' => 'italian',
31
61
  'ja' => 'japanese',
62
+ 'jv' => 'javanese',
63
+ 'jw' => 'javanese',
64
+ 'kn' => 'kannada',
65
+ 'kk' => 'kazakh',
66
+ 'km' => 'khmer',
67
+ 'rw' => 'kinyarwanda',
68
+ 'gom' => 'konkani',
32
69
  'ko' => 'korean',
70
+ 'kri' => 'krio',
71
+ 'ku' => 'kurdish_kurmanji',
72
+ 'ckb' => 'kurdish_sorani',
73
+ 'ky' => 'kyrgyz',
74
+ 'lo' => 'lao',
33
75
  'la' => 'latin',
34
76
  'lv' => 'latvian',
77
+ 'ln' => 'lingala',
35
78
  'lt' => 'lithuanian',
79
+ 'lb' => 'luxembourgish',
36
80
  'mk' => 'macedonian',
81
+ 'mai' => 'maithili',
82
+ 'mg' => 'malagasy',
37
83
  'ms' => 'malay',
84
+ 'ml' => 'malayalam',
38
85
  'mt' => 'maltese',
86
+ 'mi' => 'maori',
87
+ 'mr' => 'marathi',
88
+ 'mni-Mtei' => 'meiteilon_manipuri',
89
+ 'lus' => 'mizo',
90
+ 'mn' => 'mongolian',
91
+ 'my' => 'myanmar_burmese',
92
+ 'ne' => 'nepali',
93
+ 'nso' => 'northern_sotho',
39
94
  'no' => 'norwegian',
95
+ 'or' => 'odia_oriya',
96
+ 'om' => 'oromo',
97
+ 'ps' => 'pashto',
40
98
  'fa' => 'persian',
41
99
  'pl' => 'polish',
42
100
  'pt' => 'portuguese',
101
+ 'pa' => 'punjabi',
102
+ 'qu' => 'quechua',
43
103
  'ro' => 'romanian',
44
104
  'ru' => 'russian',
105
+ 'sm' => 'samoan',
106
+ 'sa' => 'sanskrit',
107
+ 'gd' => 'scots_gaelic',
45
108
  'sr' => 'serbian',
109
+ 'st' => 'sesotho',
110
+ 'sn' => 'shona',
111
+ 'sd' => 'sindhi',
112
+ 'si' => 'sinhala',
46
113
  'sk' => 'slovak',
47
114
  'sl' => 'slovenian',
115
+ 'so' => 'somali',
48
116
  'es' => 'spanish',
117
+ 'su' => 'sundanese',
49
118
  'sw' => 'swahili',
50
119
  'sv' => 'swedish',
120
+ 'tg' => 'tajik',
121
+ 'ta' => 'tamil',
122
+ 'tt' => 'tatar',
123
+ 'te' => 'telugu',
51
124
  'th' => 'thai',
125
+ 'ti' => 'tigrinya',
126
+ 'ts' => 'tsonga',
52
127
  'tr' => 'turkish',
128
+ 'tk' => 'turkmen',
129
+ 'ak' => 'twi',
53
130
  'uk' => 'ukrainian',
131
+ 'ur' => 'urdu',
132
+ 'ug' => 'uyghur',
133
+ 'uz' => 'uzbek',
54
134
  'vi' => 'vietnamese',
55
135
  'cy' => 'welsh',
56
- 'yi' => 'yiddish'
136
+ 'xh' => 'xhosa',
137
+ 'yi' => 'yiddish',
138
+ 'yo' => 'yoruba',
139
+ 'zu' => 'zulu'
57
140
  }
58
141
 
59
142
  end
@@ -36,21 +36,23 @@ module EasyTranslate
36
36
  # Perform the given request
37
37
  # @return [String] The response String
38
38
  def perform_raw
39
- # Construct the request
40
- request = Net::HTTP::Post.new(uri.request_uri)
41
- request.add_field('X-HTTP-Method-Override', 'GET')
39
+ request = Net::HTTP::Post.new(uri.request_uri, { 'Content-Type' => 'application/json' })
42
40
  request.body = body
43
- # Fire and return
44
41
  response = http.request(request)
45
- unless response.code == '200'
46
- err = JSON.parse(response.body)['error']['errors'].first['message']
47
- raise EasyTranslateException.new(err)
48
- end
42
+ raise_exception(response) unless response.code == '200'
49
43
  response.body
50
44
  end
51
45
 
52
46
  private
53
47
 
48
+ def raise_exception(response)
49
+ err = JSON.parse(response.body)['error']['errors'].first['message']
50
+ rescue JSON::ParserError => _e
51
+ err = "#{response.code} - #{response.message}"
52
+ ensure
53
+ raise EasyTranslateException.new(err)
54
+ end
55
+
54
56
  def uri
55
57
  @uri ||= URI.parse("https://translation.googleapis.com#{path}?#{param_s}")
56
58
  end
@@ -81,9 +81,9 @@ module EasyTranslate
81
81
  end
82
82
 
83
83
  # The body for the request
84
- # @return [String] the body for the request, URL escaped
84
+ # @return [String] the body for the request
85
85
  def body
86
- @texts.map { |t| "q=#{CGI::escape(t)}" }.join '&'
86
+ JSON.generate({ q: @texts })
87
87
  end
88
88
 
89
89
  # Whether or not this was a request for multiple texts
@@ -12,9 +12,13 @@ module EasyTranslate
12
12
  def translations_available(target = nil, options = {})
13
13
  request = TranslationTargetRequest.new(target, options)
14
14
  raw = request.perform_raw
15
- JSON.parse(raw)['data']['languages'].map do |res|
15
+ languages = JSON.parse(raw)['data']['languages'].map do |res|
16
16
  res['language']
17
17
  end
18
+
19
+ languages.push('zh-CN') if !languages.index('zh').nil?
20
+
21
+ languages
18
22
  end
19
23
 
20
24
  class TranslationTargetRequest < EasyTranslate::Request
@@ -1,5 +1,5 @@
1
1
  module EasyTranslate
2
2
 
3
- VERSION = '0.5.1'
3
+ VERSION = '0.5.2'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Crepezzi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-15 00:00:00.000000000 Z
11
+ date: 2026-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: thread
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -73,7 +87,7 @@ homepage: https://github.com/seejohnrun/easy_translate
73
87
  licenses:
74
88
  - MIT
75
89
  metadata: {}
76
- post_install_message:
90
+ post_install_message:
77
91
  rdoc_options: []
78
92
  require_paths:
79
93
  - lib
@@ -88,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  requirements: []
91
- rubyforge_project:
92
- rubygems_version: 2.6.14
93
- signing_key:
105
+ rubygems_version: 3.1.6
106
+ signing_key:
94
107
  specification_version: 4
95
108
  summary: Google Translate API Wrapper for Ruby
96
109
  test_files: