deepl-rb 2.3.1 → 2.5.1
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 +4 -4
- data/.rubocop.yml +7 -4
- data/README.md +100 -1
- data/VERSION +1 -1
- data/deepl-rb.gemspec +25 -4
- data/lib/deepl/configuration.rb +2 -2
- data/lib/deepl/exceptions/not_found.rb +13 -0
- data/lib/deepl/exceptions/not_supported.rb +11 -0
- data/lib/deepl/glossary_api.rb +35 -0
- data/lib/deepl/requests/base.rb +21 -4
- data/lib/deepl/requests/glossary/create.rb +45 -0
- data/lib/deepl/requests/glossary/destroy.rb +30 -0
- data/lib/deepl/requests/glossary/entries.rb +30 -0
- data/lib/deepl/requests/glossary/find.rb +31 -0
- data/lib/deepl/requests/glossary/language_pairs.rb +31 -0
- data/lib/deepl/requests/glossary/list.rb +30 -0
- data/lib/deepl/requests/languages.rb +3 -1
- data/lib/deepl/requests/translate.rb +4 -2
- data/lib/deepl/resources/glossary.rb +25 -0
- data/lib/deepl/resources/language.rb +8 -1
- data/lib/deepl/resources/language_pair.rb +20 -0
- data/lib/deepl.rb +16 -0
- data/spec/api/configuration_spec.rb +1 -1
- data/spec/api/deepl_spec.rb +189 -0
- data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +374 -0
- data/spec/fixtures/vcr_cassettes/deepl_languages.yml +3 -1
- data/spec/fixtures/vcr_cassettes/deepl_translate.yml +212 -1
- data/spec/fixtures/vcr_cassettes/deepl_usage.yml +3 -1
- data/spec/fixtures/vcr_cassettes/glossaries.yml +480 -0
- data/spec/fixtures/vcr_cassettes/languages.yml +9 -3
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +101 -44
- data/spec/fixtures/vcr_cassettes/usage.yml +3 -1
- data/spec/requests/glossary/create_spec.rb +55 -0
- data/spec/requests/glossary/destroy_spec.rb +50 -0
- data/spec/requests/glossary/entries_spec.rb +48 -0
- data/spec/requests/glossary/find_spec.rb +54 -0
- data/spec/requests/glossary/language_pairs_spec.rb +30 -0
- data/spec/requests/glossary/list_spec.rb +44 -0
- data/spec/requests/translate_spec.rb +74 -2
- data/spec/resources/glossary_spec.rb +35 -0
- data/spec/resources/language_pair_spec.rb +20 -0
- data/spec/resources/language_spec.rb +23 -1
- data/spec/spec_helper.rb +3 -3
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b243885998d697691ea44defaba15632cbe10a2738962c5befa1191b20edb53
|
4
|
+
data.tar.gz: 9e64eff8b57820a5f59cfc1afdde88dd16bac72f8f9de89979c1288bdc72132b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8058534d4022fe77f16c5cda86e4479a7081e7d446a53282a4742f5b4ece7e66f57f1bde6e83c30a0d6dc054477bd53e7b961147e61cd7abc815af7c4c65cc72
|
7
|
+
data.tar.gz: d07ddd8f131b597756fd00bb5e1a43bb4d4310ab3cd4650fdd2bcd4658066063280a58c8bd9c3e0cbb5399adb1013654a89aebf7cbe5fa3fe515b7b714309194
|
data/.rubocop.yml
CHANGED
@@ -4,14 +4,17 @@ AllCops:
|
|
4
4
|
DisplayCopNames: true
|
5
5
|
NewCops: enable
|
6
6
|
Exclude:
|
7
|
-
|
8
|
-
|
7
|
+
- deepl-rb.gemspec
|
8
|
+
- vendor/**/*
|
9
9
|
|
10
10
|
Metrics/BlockLength:
|
11
11
|
Exclude:
|
12
|
-
|
12
|
+
- "**/*_spec.rb"
|
13
13
|
|
14
|
-
Metrics/
|
14
|
+
Metrics/ParameterLists:
|
15
|
+
Max: 6
|
16
|
+
|
17
|
+
Layout/LineLength:
|
15
18
|
Max: 100
|
16
19
|
|
17
20
|
Style/Documentation:
|
data/README.md
CHANGED
@@ -71,7 +71,10 @@ puts DeepL.languages(type: :target).count
|
|
71
71
|
```
|
72
72
|
|
73
73
|
All languages are also defined on the
|
74
|
-
[official API documentation](https://www.deepl.com/docs-api/translating-text/)
|
74
|
+
[official API documentation](https://www.deepl.com/docs-api/translating-text/).
|
75
|
+
|
76
|
+
Note that target languages may include the `supports_formality` flag, which may be checked
|
77
|
+
using the `DeepL::Resources::Language#supports_formality?`.
|
75
78
|
|
76
79
|
### Translate
|
77
80
|
|
@@ -125,11 +128,106 @@ The following parameters will be automatically converted:
|
|
125
128
|
| `preserve_formatting` | Converts `false` to `'0'` and `true` to `'1'`
|
126
129
|
| `split_sentences` | Converts `false` to `'0'` and `true` to `'1'`
|
127
130
|
| `outline_detection` | Converts `false` to `'0'` and `true` to `'1'`
|
131
|
+
| `splitting_tags` | Converts arrays to strings joining by commas
|
128
132
|
| `non_splitting_tags` | Converts arrays to strings joining by commas
|
129
133
|
| `ignore_tags` | Converts arrays to strings joining by commas
|
130
134
|
| `formality` | No conversion applied
|
131
135
|
| `glossary_id` | No conversion applied
|
132
136
|
|
137
|
+
### Glossaries
|
138
|
+
|
139
|
+
To create a glossary, use the `glossaries.create` method. The glossary `entries` argument should be an array of text pairs. Each pair includes the source and the target translations.
|
140
|
+
|
141
|
+
```rb
|
142
|
+
entries = [
|
143
|
+
['Hello World', 'Hola Tierra'],
|
144
|
+
['car', 'auto']
|
145
|
+
]
|
146
|
+
glossary = DeepL.glossaries.create 'Mi Glosario', 'EN', 'ES', entries
|
147
|
+
|
148
|
+
puts glossary.class
|
149
|
+
# => DeepL::Resources::Glossary
|
150
|
+
puts glossary.id
|
151
|
+
# => 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
|
152
|
+
puts glossary.entry_count
|
153
|
+
# => 2
|
154
|
+
```
|
155
|
+
|
156
|
+
Created glossaries can be used in the `translate` method by specifying the `glossary_id` option:
|
157
|
+
|
158
|
+
```rb
|
159
|
+
translation = DeepL.translate 'Hello World', 'EN', 'ES', glossary_id: 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
|
160
|
+
|
161
|
+
puts translation.class
|
162
|
+
# => DeepL::Resources::Text
|
163
|
+
puts translation.text
|
164
|
+
# => 'Hola Tierra'
|
165
|
+
|
166
|
+
translation = DeepL.translate "I wish we had a car.", 'EN', 'ES', glossary_id: 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
|
167
|
+
|
168
|
+
puts translation.class
|
169
|
+
# => DeepL::Resources::Text
|
170
|
+
puts translation.text
|
171
|
+
# => Ojalá tuviéramos un auto.
|
172
|
+
```
|
173
|
+
|
174
|
+
To list all the glossaries available, use the `glossaries.list` method:
|
175
|
+
|
176
|
+
```rb
|
177
|
+
glossaries = DeepL.glossaries.list
|
178
|
+
|
179
|
+
puts glossaries.class
|
180
|
+
# => Array
|
181
|
+
puts glossaries.first.class
|
182
|
+
# => DeepL::Resources::Glossary
|
183
|
+
```
|
184
|
+
|
185
|
+
To find an existing glossary, use the `glossaries.find` method:
|
186
|
+
|
187
|
+
```rb
|
188
|
+
glossary = DeepL.glossaries.find 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
|
189
|
+
|
190
|
+
puts glossary.class
|
191
|
+
# => DeepL::Resources::Glossary
|
192
|
+
```
|
193
|
+
|
194
|
+
The glossary resource does not include the glossary entries. To list the glossary entries, use the `glossaries.entries` method:
|
195
|
+
|
196
|
+
```rb
|
197
|
+
entries = DeepL.glossaries.entries 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
|
198
|
+
|
199
|
+
puts entries.class
|
200
|
+
# => Array
|
201
|
+
puts entries.size
|
202
|
+
# => 2
|
203
|
+
pp entries.first
|
204
|
+
# => ["Hello World", "Hola Tierra"]
|
205
|
+
```
|
206
|
+
|
207
|
+
To delete an existing glossary, use the `glossaries.destroy` method:
|
208
|
+
|
209
|
+
```rb
|
210
|
+
glossary_id = DeepL.glossaries.destroy 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
|
211
|
+
|
212
|
+
puts glossary_id
|
213
|
+
# => aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e
|
214
|
+
```
|
215
|
+
|
216
|
+
You can list all the language pairs supported by glossaries using the `glossaries.language_pairs` method:
|
217
|
+
|
218
|
+
```rb
|
219
|
+
language_pairs = DeepL.glossaries.language_pairs
|
220
|
+
|
221
|
+
puts language_pairs.class
|
222
|
+
# => Array
|
223
|
+
puts language_pairs.first.class
|
224
|
+
# => DeepL::Resources::LanguagePair
|
225
|
+
puts language_pairs.first.source_lang
|
226
|
+
# => en
|
227
|
+
puts language_pairs.first.target_lang
|
228
|
+
# => de
|
229
|
+
```
|
230
|
+
|
133
231
|
### Monitor usage
|
134
232
|
|
135
233
|
To check current API usage, use:
|
@@ -154,6 +252,7 @@ You can capture and process exceptions that may be raised during API calls. Thes
|
|
154
252
|
| `DeepL::Exceptions::LimitExceeded` | You've reached the API's call limit. |
|
155
253
|
| `DeepL::Exceptions::QuotaExceeded` | You've reached the API's character limit. |
|
156
254
|
| `DeepL::Exceptions::RequestError` | An unkown request error. Check `exception.response` and `exception.request` for more information. |
|
255
|
+
| `DeepL::Exceptions::NotSupported` | The requested method or API endpoint is not supported. |
|
157
256
|
|
158
257
|
An exampling of handling a generic exception:
|
159
258
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.1
|
data/deepl-rb.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: deepl-rb 2.
|
5
|
+
# stub: deepl-rb 2.5.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "deepl-rb".freeze
|
9
|
-
s.version = "2.
|
9
|
+
s.version = "2.5.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Daniel Herzog".freeze]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2022-06-22"
|
15
15
|
s.description = "A simple ruby wrapper for the DeepL translation API (v1). For more information, check this: https://www.deepl.com/docs/api-reference.html".freeze
|
16
16
|
s.email = "info@danielherzog.es".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -34,28 +34,49 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/deepl/exceptions/bad_request.rb",
|
35
35
|
"lib/deepl/exceptions/error.rb",
|
36
36
|
"lib/deepl/exceptions/limit_exceeded.rb",
|
37
|
+
"lib/deepl/exceptions/not_found.rb",
|
38
|
+
"lib/deepl/exceptions/not_supported.rb",
|
37
39
|
"lib/deepl/exceptions/quota_exceeded.rb",
|
38
40
|
"lib/deepl/exceptions/request_error.rb",
|
41
|
+
"lib/deepl/glossary_api.rb",
|
39
42
|
"lib/deepl/requests/base.rb",
|
43
|
+
"lib/deepl/requests/glossary/create.rb",
|
44
|
+
"lib/deepl/requests/glossary/destroy.rb",
|
45
|
+
"lib/deepl/requests/glossary/entries.rb",
|
46
|
+
"lib/deepl/requests/glossary/find.rb",
|
47
|
+
"lib/deepl/requests/glossary/language_pairs.rb",
|
48
|
+
"lib/deepl/requests/glossary/list.rb",
|
40
49
|
"lib/deepl/requests/languages.rb",
|
41
50
|
"lib/deepl/requests/translate.rb",
|
42
51
|
"lib/deepl/requests/usage.rb",
|
43
52
|
"lib/deepl/resources/base.rb",
|
53
|
+
"lib/deepl/resources/glossary.rb",
|
44
54
|
"lib/deepl/resources/language.rb",
|
55
|
+
"lib/deepl/resources/language_pair.rb",
|
45
56
|
"lib/deepl/resources/text.rb",
|
46
57
|
"lib/deepl/resources/usage.rb",
|
47
58
|
"spec/api/api_spec.rb",
|
48
59
|
"spec/api/configuration_spec.rb",
|
49
60
|
"spec/api/deepl_spec.rb",
|
61
|
+
"spec/fixtures/vcr_cassettes/deepl_glossaries.yml",
|
50
62
|
"spec/fixtures/vcr_cassettes/deepl_languages.yml",
|
51
63
|
"spec/fixtures/vcr_cassettes/deepl_translate.yml",
|
52
64
|
"spec/fixtures/vcr_cassettes/deepl_usage.yml",
|
65
|
+
"spec/fixtures/vcr_cassettes/glossaries.yml",
|
53
66
|
"spec/fixtures/vcr_cassettes/languages.yml",
|
54
67
|
"spec/fixtures/vcr_cassettes/translate_texts.yml",
|
55
68
|
"spec/fixtures/vcr_cassettes/usage.yml",
|
69
|
+
"spec/requests/glossary/create_spec.rb",
|
70
|
+
"spec/requests/glossary/destroy_spec.rb",
|
71
|
+
"spec/requests/glossary/entries_spec.rb",
|
72
|
+
"spec/requests/glossary/find_spec.rb",
|
73
|
+
"spec/requests/glossary/language_pairs_spec.rb",
|
74
|
+
"spec/requests/glossary/list_spec.rb",
|
56
75
|
"spec/requests/languages_spec.rb",
|
57
76
|
"spec/requests/translate_spec.rb",
|
58
77
|
"spec/requests/usage_spec.rb",
|
78
|
+
"spec/resources/glossary_spec.rb",
|
79
|
+
"spec/resources/language_pair_spec.rb",
|
59
80
|
"spec/resources/language_spec.rb",
|
60
81
|
"spec/resources/text_spec.rb",
|
61
82
|
"spec/resources/usage_spec.rb",
|
@@ -63,7 +84,7 @@ Gem::Specification.new do |s|
|
|
63
84
|
]
|
64
85
|
s.homepage = "http://github.com/wikiti/deepl-rb".freeze
|
65
86
|
s.licenses = ["MIT".freeze]
|
66
|
-
s.rubygems_version = "3.
|
87
|
+
s.rubygems_version = "3.3.7".freeze
|
67
88
|
s.summary = "A simple ruby wrapper for the DeepL API".freeze
|
68
89
|
|
69
90
|
if s.respond_to? :specification_version then
|
data/lib/deepl/configuration.rb
CHANGED
@@ -8,7 +8,7 @@ module DeepL
|
|
8
8
|
|
9
9
|
def initialize(data = {})
|
10
10
|
data.each { |key, value| send("#{key}=", value) }
|
11
|
-
@auth_key ||= ENV
|
11
|
+
@auth_key ||= ENV.fetch('DEEPL_AUTH_KEY', nil)
|
12
12
|
@host ||= 'https://api.deepl.com'
|
13
13
|
@version ||= 'v2'
|
14
14
|
end
|
@@ -18,7 +18,7 @@ module DeepL
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def attributes
|
21
|
-
ATTRIBUTES.
|
21
|
+
ATTRIBUTES.to_h { |attr| [attr, send(attr)] }
|
22
22
|
end
|
23
23
|
|
24
24
|
def ==(other)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
class GlossaryApi
|
5
|
+
def initialize(api, options = {})
|
6
|
+
@api = api
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(name, source_lang, target_lang, entries, options = {})
|
11
|
+
DeepL::Requests::Glossary::Create.new(@api, name, source_lang, target_lang, entries, options)
|
12
|
+
.request
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy(glossary_id, options = {})
|
16
|
+
DeepL::Requests::Glossary::Destroy.new(@api, glossary_id, options).request
|
17
|
+
end
|
18
|
+
|
19
|
+
def entries(glossary_id, options = {})
|
20
|
+
DeepL::Requests::Glossary::Entries.new(@api, glossary_id, options).request
|
21
|
+
end
|
22
|
+
|
23
|
+
def find(glossary_id, options = {})
|
24
|
+
DeepL::Requests::Glossary::Find.new(@api, glossary_id, options).request
|
25
|
+
end
|
26
|
+
|
27
|
+
def language_pairs(options = {})
|
28
|
+
DeepL::Requests::Glossary::LanguagePairs.new(@api, options).request
|
29
|
+
end
|
30
|
+
|
31
|
+
def list(options = {})
|
32
|
+
DeepL::Requests::Glossary::List.new(@api, options).request
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/deepl/requests/base.rb
CHANGED
@@ -24,6 +24,10 @@ module DeepL
|
|
24
24
|
options[name.to_s] || options[name.to_sym]
|
25
25
|
end
|
26
26
|
|
27
|
+
def delete_option(name)
|
28
|
+
options.delete(name.to_s) || options.delete(name.to_sym)
|
29
|
+
end
|
30
|
+
|
27
31
|
def set_option(name, value)
|
28
32
|
if options.key?(name.to_sym)
|
29
33
|
options[name.to_sym] = value
|
@@ -33,7 +37,7 @@ module DeepL
|
|
33
37
|
end
|
34
38
|
|
35
39
|
def post(payload)
|
36
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
40
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
37
41
|
request.set_form_data(payload.compact)
|
38
42
|
response = http.request(request)
|
39
43
|
|
@@ -42,7 +46,15 @@ module DeepL
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def get
|
45
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
49
|
+
request = Net::HTTP::Get.new(uri.request_uri, headers)
|
50
|
+
response = http.request(request)
|
51
|
+
|
52
|
+
validate_response!(request, response)
|
53
|
+
[request, response]
|
54
|
+
end
|
55
|
+
|
56
|
+
def delete
|
57
|
+
request = Net::HTTP::Delete.new(uri.request_uri, headers)
|
46
58
|
response = http.request(request)
|
47
59
|
|
48
60
|
validate_response!(request, response)
|
@@ -62,7 +74,8 @@ module DeepL
|
|
62
74
|
|
63
75
|
case response.code
|
64
76
|
when '400' then raise Exceptions::BadRequest.new(request, response)
|
65
|
-
when '403' then raise Exceptions::AuthorizationFailed.new(request, response)
|
77
|
+
when '401', '403' then raise Exceptions::AuthorizationFailed.new(request, response)
|
78
|
+
when '404' then raise Exceptions::NotFound.new(request, response)
|
66
79
|
when '429' then raise Exceptions::LimitExceeded.new(request, response)
|
67
80
|
when '456' then raise Exceptions::QuotaExceeded.new(request, response)
|
68
81
|
else raise Exceptions::RequestError.new(request, response)
|
@@ -91,7 +104,11 @@ module DeepL
|
|
91
104
|
end
|
92
105
|
|
93
106
|
def query_params
|
94
|
-
|
107
|
+
options
|
108
|
+
end
|
109
|
+
|
110
|
+
def headers
|
111
|
+
{ 'Authorization' => "DeepL-Auth-Key #{api.configuration.auth_key}" }
|
95
112
|
end
|
96
113
|
end
|
97
114
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Requests
|
5
|
+
module Glossary
|
6
|
+
class Create < Base
|
7
|
+
attr_reader :name, :source_lang, :target_lang, :entries, :entries_format
|
8
|
+
|
9
|
+
def initialize(api, name, source_lang, target_lang, entries, options = {})
|
10
|
+
super(api, options)
|
11
|
+
@name = name
|
12
|
+
@source_lang = source_lang
|
13
|
+
@target_lang = target_lang
|
14
|
+
@entries = entries
|
15
|
+
@entries_format = delete_option(:entries_format) || 'tsv'
|
16
|
+
end
|
17
|
+
|
18
|
+
def request
|
19
|
+
payload = {
|
20
|
+
name: name, source_lang: source_lang, target_lang: target_lang, entries: entries_to_tsv,
|
21
|
+
entries_format: entries_format
|
22
|
+
}
|
23
|
+
build_glossary(*post(payload))
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def entries_to_tsv
|
29
|
+
return entries if entries.is_a?(String)
|
30
|
+
|
31
|
+
entries.reduce('') { |tsv, entry| "#{tsv}#{entry.first}\t#{entry.last}\n" }
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_glossary(request, response)
|
35
|
+
glossary = JSON.parse(response.body)
|
36
|
+
Resources::Glossary.new(glossary, request, response)
|
37
|
+
end
|
38
|
+
|
39
|
+
def path
|
40
|
+
'glossaries'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Requests
|
5
|
+
module Glossary
|
6
|
+
class Destroy < Base
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
def initialize(api, id, options = {})
|
10
|
+
super(api, options)
|
11
|
+
@id = id
|
12
|
+
end
|
13
|
+
|
14
|
+
def request
|
15
|
+
build_response(*delete)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def build_response(_, _)
|
21
|
+
id
|
22
|
+
end
|
23
|
+
|
24
|
+
def path
|
25
|
+
"glossaries/#{id}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Requests
|
5
|
+
module Glossary
|
6
|
+
class Entries < Base
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
def initialize(api, id, options = {})
|
10
|
+
super(api, options)
|
11
|
+
@id = id
|
12
|
+
end
|
13
|
+
|
14
|
+
def request
|
15
|
+
build_entries(*get)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def build_entries(_, response)
|
21
|
+
response.body.split("\n").map { |entry| entry.split("\t") }
|
22
|
+
end
|
23
|
+
|
24
|
+
def path
|
25
|
+
"glossaries/#{id}/entries"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Requests
|
5
|
+
module Glossary
|
6
|
+
class Find < Base
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
def initialize(api, id, options = {})
|
10
|
+
super(api, options)
|
11
|
+
@id = id
|
12
|
+
end
|
13
|
+
|
14
|
+
def request
|
15
|
+
build_glossary(*get)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def build_glossary(request, response)
|
21
|
+
glossary = JSON.parse(response.body)
|
22
|
+
Resources::Glossary.new(glossary, request, response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def path
|
26
|
+
"glossaries/#{id}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Requests
|
5
|
+
module Glossary
|
6
|
+
class LanguagePairs < Base
|
7
|
+
def initialize(api, options = {})
|
8
|
+
super(api, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def request
|
12
|
+
build_language_pair_list(*get)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_language_pair_list(request, response)
|
18
|
+
data = JSON.parse(response.body)
|
19
|
+
data['supported_languages'].map do |language_pair|
|
20
|
+
Resources::LanguagePair.new(language_pair['source_lang'], language_pair['target_lang'],
|
21
|
+
request, response)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def path
|
26
|
+
'glossary-language-pairs'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Requests
|
5
|
+
module Glossary
|
6
|
+
class List < Base
|
7
|
+
def initialize(api, options = {})
|
8
|
+
super(api, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def request
|
12
|
+
build_glossary_list(*get)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_glossary_list(request, response)
|
18
|
+
data = JSON.parse(response.body)
|
19
|
+
data['glossaries'].map do |glossary|
|
20
|
+
Resources::Glossary.new(glossary, request, response)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def path
|
25
|
+
'glossaries'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -16,7 +16,9 @@ module DeepL
|
|
16
16
|
def build_languages(request, response)
|
17
17
|
data = JSON.parse(response.body)
|
18
18
|
data.map do |language|
|
19
|
-
Resources::Language.new(language['language'], language['name'],
|
19
|
+
Resources::Language.new(language['language'], language['name'],
|
20
|
+
language['supports_formality'],
|
21
|
+
request, response)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -4,16 +4,18 @@ module DeepL
|
|
4
4
|
module Requests
|
5
5
|
class Translate < Base
|
6
6
|
BOOLEAN_CONVERSION = { true => '1', false => '0' }.freeze
|
7
|
-
ARRAY_CONVERSION = ->(value) { value.is_a?(Array) ? value.join(',
|
7
|
+
ARRAY_CONVERSION = ->(value) { value.is_a?(Array) ? value.join(',') : value }.freeze
|
8
8
|
OPTIONS_CONVERSIONS = {
|
9
9
|
split_sentences: BOOLEAN_CONVERSION,
|
10
10
|
preserve_formatting: BOOLEAN_CONVERSION,
|
11
11
|
outline_detection: BOOLEAN_CONVERSION,
|
12
|
+
splitting_tags: ARRAY_CONVERSION,
|
12
13
|
non_splitting_tags: ARRAY_CONVERSION,
|
13
14
|
ignore_tags: ARRAY_CONVERSION
|
14
15
|
}.freeze
|
15
16
|
|
16
|
-
attr_reader :text, :source_lang, :target_lang, :ignore_tags, :
|
17
|
+
attr_reader :text, :source_lang, :target_lang, :ignore_tags, :splitting_tags,
|
18
|
+
:non_splitting_tags
|
17
19
|
|
18
20
|
def initialize(api, text, source_lang, target_lang, options = {})
|
19
21
|
super(api, options)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Resources
|
5
|
+
class Glossary < Base
|
6
|
+
attr_reader :id, :name, :ready, :source_lang, :target_lang, :creation_time, :entry_count
|
7
|
+
|
8
|
+
def initialize(glossary, *args)
|
9
|
+
super(*args)
|
10
|
+
|
11
|
+
@id = glossary['glossary_id']
|
12
|
+
@name = glossary['name']
|
13
|
+
@ready = glossary['ready']
|
14
|
+
@source_lang = glossary['source_lang']
|
15
|
+
@target_lang = glossary['target_lang']
|
16
|
+
@creation_time = glossary['creation_time']
|
17
|
+
@entry_count = glossary['entry_count']
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"#{id} - #{name}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -5,16 +5,23 @@ module DeepL
|
|
5
5
|
class Language < Base
|
6
6
|
attr_reader :code, :name
|
7
7
|
|
8
|
-
def initialize(code, name, *args)
|
8
|
+
def initialize(code, name, supports_formality, *args)
|
9
9
|
super(*args)
|
10
10
|
|
11
11
|
@code = code
|
12
12
|
@name = name
|
13
|
+
@supports_formality = supports_formality
|
13
14
|
end
|
14
15
|
|
15
16
|
def to_s
|
16
17
|
"#{code} - #{name}"
|
17
18
|
end
|
19
|
+
|
20
|
+
def supports_formality?
|
21
|
+
return @supports_formality unless @supports_formality.nil?
|
22
|
+
|
23
|
+
raise Exceptions::NotSupported, 'Support formality is only available on target languages'
|
24
|
+
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|