deepl-rb 3.10.0 → 4.0.0
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 +1 -1
- data/CHANGELOG.md +313 -1
- data/README.md +225 -309
- data/Rakefile +17 -8
- data/VERSION +1 -1
- data/deepl-rb.gemspec +73 -86
- data/lib/deepl/admin_client.rb +39 -14
- data/lib/deepl/api.rb +3 -17
- data/lib/deepl/app_info.rb +0 -1
- data/lib/deepl/client.rb +399 -84
- data/lib/deepl/configuration.rb +19 -70
- data/lib/deepl/exceptions/authorization_failed.rb +1 -1
- data/lib/deepl/exceptions/connection_error.rb +10 -7
- data/lib/deepl/exceptions/limit_exceeded.rb +1 -1
- data/lib/deepl/exceptions/quota_exceeded.rb +1 -1
- data/lib/deepl/exceptions/request_entity_too_large.rb +1 -2
- data/lib/deepl/exceptions/request_error.rb +7 -0
- data/lib/deepl/exceptions/server_error.rb +2 -1
- data/lib/deepl/exceptions/translation_memory_job_error.rb +32 -0
- data/lib/deepl/exceptions/validation_error.rb +3 -2
- data/lib/deepl/requests/base.rb +129 -51
- data/lib/deepl/requests/correct.rb +2 -8
- data/lib/deepl/requests/document/upload.rb +29 -26
- data/lib/deepl/requests/glossary/base.rb +30 -0
- data/lib/deepl/requests/glossary/create.rb +18 -22
- data/lib/deepl/requests/glossary/destroy.rb +4 -16
- data/lib/deepl/requests/glossary/entries.rb +6 -14
- data/lib/deepl/requests/glossary/find.rb +3 -13
- data/lib/deepl/requests/glossary/language_pairs.rb +2 -2
- data/lib/deepl/requests/glossary/list.rb +2 -2
- data/lib/deepl/requests/languages.rb +6 -11
- data/lib/deepl/requests/languages_for_resource.rb +2 -0
- data/lib/deepl/requests/multilingual_glossary/create.rb +8 -0
- data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +4 -0
- data/lib/deepl/requests/multilingual_glossary/entries.rb +5 -3
- data/lib/deepl/requests/multilingual_glossary/helpers.rb +22 -14
- data/lib/deepl/requests/rephrase.rb +3 -1
- data/lib/deepl/requests/spoken_terms/create.rb +5 -0
- data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +1 -0
- data/lib/deepl/requests/spoken_terms/entries.rb +1 -0
- data/lib/deepl/requests/spoken_terms/helpers.rb +9 -2
- data/lib/deepl/requests/style_profile/create.rb +5 -0
- data/lib/deepl/requests/style_profile/list.rb +2 -2
- data/lib/deepl/requests/style_rule/create.rb +25 -1
- data/lib/deepl/requests/style_rule/create_custom_instruction.rb +7 -0
- data/lib/deepl/requests/style_rule/helpers.rb +13 -4
- data/lib/deepl/requests/style_rule/list.rb +2 -0
- data/lib/deepl/requests/style_rule/update.rb +1 -0
- data/lib/deepl/requests/style_rule/update_custom_instruction.rb +2 -0
- data/lib/deepl/requests/translate.rb +20 -36
- data/lib/deepl/requests/translation_memory/create_export.rb +6 -1
- data/lib/deepl/requests/translation_memory/create_import.rb +10 -0
- data/lib/deepl/requests/translation_memory/download_export.rb +0 -4
- data/lib/deepl/requests/translation_memory/list.rb +2 -2
- data/lib/deepl/requests/translation_memory/segments.rb +2 -2
- data/lib/deepl/requests/translation_memory/storage_base.rb +5 -9
- data/lib/deepl/requests/write_improvements.rb +7 -0
- data/lib/deepl/resources/document_handle.rb +1 -26
- data/lib/deepl/resources/document_translation_status.rb +0 -12
- data/lib/deepl/resources/language.rb +4 -10
- data/lib/deepl/resources/multilingual_glossary.rb +4 -4
- data/lib/deepl/resources/style_rule.rb +1 -23
- data/lib/deepl/resources/translation_memory_job.rb +3 -4
- data/lib/deepl/resources/usage.rb +5 -38
- data/lib/deepl/utils/client_builder.rb +44 -9
- data/lib/deepl/utils/glossary_entries.rb +30 -0
- data/lib/deepl/utils/http_client_builder.rb +50 -13
- data/lib/deepl/utils/output_path.rb +25 -0
- data/lib/deepl/utils/term_validator.rb +3 -3
- data/lib/deepl/utils/translation_memory_operations.rb +230 -0
- data/lib/deepl.rb +6 -171
- data/lib/http_client_options.rb +2 -2
- data/lib/version.rb +1 -1
- data/upgrading_to_v4.md +374 -0
- metadata +9 -50
- data/.gitlab-ci.yml +0 -197
- data/lib/deepl/deprecation.rb +0 -42
- data/lib/deepl/document_api.rb +0 -150
- data/lib/deepl/exceptions/not_supported.rb +0 -20
- data/lib/deepl/glossary_api.rb +0 -38
- data/lib/deepl/style_rule_api.rb +0 -72
- data/lib/deepl/translation_memory_api.rb +0 -389
- data/license_checker.sh +0 -8
- data/spec/fixtures.rb +0 -33
- data/spec/offline/admin_client_spec.rb +0 -551
- data/spec/offline/client_spec.rb +0 -273
- data/spec/offline/configuration_spec.rb +0 -164
- data/spec/offline/constants_spec.rb +0 -180
- data/spec/offline/correct_text_spec.rb +0 -50
- data/spec/offline/deprecation_spec.rb +0 -32
- data/spec/offline/errors_spec.rb +0 -92
- data/spec/offline/glossaries_spec.rb +0 -98
- data/spec/offline/http_client_spec.rb +0 -319
- data/spec/offline/languages_spec.rb +0 -155
- data/spec/offline/module_methods_spec.rb +0 -13
- data/spec/offline/multilingual_glossaries_spec.rb +0 -358
- data/spec/offline/offline_helper.rb +0 -71
- data/spec/offline/rephrase_text_spec.rb +0 -73
- data/spec/offline/spoken_terms_spec.rb +0 -215
- data/spec/offline/style_profiles_spec.rb +0 -266
- data/spec/offline/style_rules_spec.rb +0 -318
- data/spec/offline/translate_document_spec.rb +0 -606
- data/spec/offline/translate_text_spec.rb +0 -286
- data/spec/offline/translation_memories_client_spec.rb +0 -256
- data/spec/offline/translation_memories_spec.rb +0 -463
- data/spec/offline/usage_spec.rb +0 -151
- data/spec/real_api/admin_client_spec.rb +0 -77
- data/spec/real_api/correct_text_spec.rb +0 -20
- data/spec/real_api/glossaries_spec.rb +0 -28
- data/spec/real_api/languages_spec.rb +0 -27
- data/spec/real_api/multilingual_glossaries_spec.rb +0 -53
- data/spec/real_api/proxy_spec.rb +0 -41
- data/spec/real_api/real_api_helper.rb +0 -65
- data/spec/real_api/rephrase_text_spec.rb +0 -16
- data/spec/real_api/spoken_terms_spec.rb +0 -56
- data/spec/real_api/style_profiles_spec.rb +0 -46
- data/spec/real_api/style_rules_spec.rb +0 -46
- data/spec/real_api/translate_document_spec.rb +0 -18
- data/spec/real_api/translate_text_spec.rb +0 -16
- data/spec/real_api/translation_memories_spec.rb +0 -56
- data/spec/real_api/usage_spec.rb +0 -20
- data/spec/spec_helper.rb +0 -13
data/upgrading_to_v4.md
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
# Upgrading to 4.0.0
|
|
2
|
+
|
|
3
|
+
Version 4.0.0 removes everything that 3.10.0 deprecated, most of all the module-level API
|
|
4
|
+
(`DeepL.configure`, `DeepL.translate`, `DeepL.glossaries`, ...). If your code calls methods on
|
|
5
|
+
the `DeepL` module, it must move to `DeepL::Client`. Code that already uses `DeepL::Client`
|
|
6
|
+
needs smaller changes: stricter option and argument checks, different retry behaviour for calls
|
|
7
|
+
that create resources, and a few changed error classes and return values. Ruby 3.0 or later is
|
|
8
|
+
now required. The full list of changes is in the [CHANGELOG](CHANGELOG.md).
|
|
9
|
+
|
|
10
|
+
To find deprecated calls before you upgrade, run your tests on 3.10.0 and fix every deprecation
|
|
11
|
+
warning.
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- Ruby 3.0 or later. The gem declares `required_ruby_version >= 3.0`; on Ruby 2.x, stay on
|
|
16
|
+
deepl-rb 3.x.
|
|
17
|
+
- No runtime gem dependency was added or removed.
|
|
18
|
+
- An `https://` proxy needs net-http 0.5.0 or later (bundled with Ruby 3.4). On Ruby 3.0 to 3.3,
|
|
19
|
+
add `gem 'net-http', '>= 0.5'` to your Gemfile. See [Client and options](#client-and-options).
|
|
20
|
+
|
|
21
|
+
## Quick checklist
|
|
22
|
+
|
|
23
|
+
1. Replace `DeepL.configure` and the module-level calls with a `DeepL::Client`:
|
|
24
|
+
[Client and options](#client-and-options).
|
|
25
|
+
2. Pass the key and server URL yourself; nothing reads `DEEPL_AUTH_KEY` or `DEEPL_SERVER_URL`:
|
|
26
|
+
[Client and options](#client-and-options).
|
|
27
|
+
3. Rename `glossary_id:` to `glossary:` for text and document translation:
|
|
28
|
+
[Text translation](#text-translation).
|
|
29
|
+
4. Fix misspelled options; unknown options now raise `ArgumentError`:
|
|
30
|
+
[Text translation](#text-translation).
|
|
31
|
+
5. Move document, glossary, style rule and translation memory calls to the `Client` methods:
|
|
32
|
+
[Documents](#documents), [Glossaries](#glossaries), [Style rules](#style-rules),
|
|
33
|
+
[Translation memories](#translation-memories).
|
|
34
|
+
6. Read usage through `usage.character`: [Usage](#usage).
|
|
35
|
+
7. Rescue `DeepL::Exceptions::ConnectionError` for network failures, and `ArgumentError` for
|
|
36
|
+
invalid arguments: [Errors, validation and retries](#errors-validation-and-retries).
|
|
37
|
+
8. Check your own retry logic around calls that create resources:
|
|
38
|
+
[Errors, validation and retries](#errors-validation-and-retries).
|
|
39
|
+
9. Do not download into an existing file: [Documents](#documents),
|
|
40
|
+
[Translation memories](#translation-memories).
|
|
41
|
+
10. Replace `configured_rules.numbers` with `configured_rules.fetch('numbers', {})`:
|
|
42
|
+
[Style rules](#style-rules).
|
|
43
|
+
|
|
44
|
+
## Client and options
|
|
45
|
+
|
|
46
|
+
The module-level API is removed: `DeepL.configure`, `DeepL.configuration`, `DeepL.api`,
|
|
47
|
+
`DeepL.http_client`, `DeepL.with_session`, and the global configuration behind them.
|
|
48
|
+
`DeepL::Configuration` is no longer public. Each `DeepL::Client` owns its configuration and
|
|
49
|
+
connection.
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
# Before (3.x)
|
|
53
|
+
DeepL.configure do |config|
|
|
54
|
+
config.auth_key = 'your-key'
|
|
55
|
+
config.host = 'https://api.deepl.com'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# After
|
|
59
|
+
client = DeepL::Client.new('your-key', server_url: 'https://api.deepl.com')
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`DeepL::Client.new(auth_key, server_url:, headers:, max_retries:, timeout:, proxy:,
|
|
63
|
+
send_platform_info:, app_info:, http_client_options:, logger:)` replaces the old settings:
|
|
64
|
+
|
|
65
|
+
| Removed | Use |
|
|
66
|
+
| ------- | --- |
|
|
67
|
+
| `DeepL.with_session`, `DeepL.http_client`, `DeepL.api` | `proxy:` and `http_client_options:` |
|
|
68
|
+
| per-call `additional_headers` | `headers:` |
|
|
69
|
+
| `config.user_agent` | `app_info:`, `send_platform_info:`, or a `User-Agent` in `headers:` |
|
|
70
|
+
| `config.version=`, `config.max_doc_status_queries=` | removed without replacement |
|
|
71
|
+
|
|
72
|
+
Changes in behaviour:
|
|
73
|
+
|
|
74
|
+
- **No environment variables.** `DEEPL_AUTH_KEY` and `DEEPL_SERVER_URL` are no longer read.
|
|
75
|
+
```ruby
|
|
76
|
+
client = DeepL::Client.new(ENV.fetch('DEEPL_AUTH_KEY'),
|
|
77
|
+
server_url: ENV.fetch('DEEPL_SERVER_URL', nil))
|
|
78
|
+
```
|
|
79
|
+
- **Default timeout** is 10 seconds per attempt; the module-level API used 60 (`DeepL::Client`
|
|
80
|
+
already used 10). Pass `timeout: 60` to keep the old value.
|
|
81
|
+
- **`server_url`** must be an absolute `http` or `https` URL with a host, otherwise
|
|
82
|
+
`ArgumentError` is raised when the client is built. Trailing slashes are removed.
|
|
83
|
+
- **Proxy** must be an `http://` or `https://` URL (String or `URI`) or a hash with `proxy_addr`
|
|
84
|
+
and `proxy_port`. Any other scheme (for example `socks5://`) or value raises `ArgumentError`.
|
|
85
|
+
An `https` proxy is now connected to over TLS, which needs net-http 0.5.0 or later and an
|
|
86
|
+
`https` server URL. Before, it was used as a plain HTTP proxy. A proxy URL with an empty host
|
|
87
|
+
(`http://`, `http://:8080`) and a proxy hash with a blank `proxy_addr` raise `ArgumentError`
|
|
88
|
+
too. This applies to `Client.new`, `AdminClient.new` and `DeepL::HTTPClientOptions`.
|
|
89
|
+
- **`nil` means the default** for `max_retries:`, `timeout:` and `send_platform_info:` (5, 10
|
|
90
|
+
seconds, `true`), like an omitted keyword. Before, `timeout: nil` used Net::HTTP's 60-second
|
|
91
|
+
timeouts and `send_platform_info: nil` left the OS and Ruby versions out of the `User-Agent`.
|
|
92
|
+
Pass `send_platform_info: false` to leave them out.
|
|
93
|
+
|
|
94
|
+
## Text translation
|
|
95
|
+
|
|
96
|
+
`DeepL.translate` and `DeepL.rephrase` are replaced by `Client#translate_text` and
|
|
97
|
+
`Client#rephrase_text`.
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
# Before (3.x)
|
|
101
|
+
DeepL.translate('Hello', 'EN', 'DE', formality: 'more')
|
|
102
|
+
DeepL.rephrase('Hello there', 'EN-US', 'business')
|
|
103
|
+
|
|
104
|
+
# After
|
|
105
|
+
client.translate_text('Hello', 'EN', 'DE', formality: 'more')
|
|
106
|
+
client.rephrase_text('Hello there', 'EN-US', writing_style: 'business')
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- `translate_text` returns an array when you pass an array, also an array with one element.
|
|
110
|
+
- `glossary_id:` is removed; use `glossary:`, which takes a glossary ID or a glossary object.
|
|
111
|
+
The same applies to document translation.
|
|
112
|
+
```ruby
|
|
113
|
+
client.translate_text('Hello', 'EN', 'DE', glossary: glossary_id)
|
|
114
|
+
```
|
|
115
|
+
- `show_billed_characters` is no longer accepted; the library always requests it.
|
|
116
|
+
- **Unknown options raise `ArgumentError`**, naming the option, before any request. Before, they
|
|
117
|
+
were sent as body fields (text, rephrase, correction, glossary, spoken terms, style rule and
|
|
118
|
+
style profile methods) or silently dropped (document translation, translation memory import).
|
|
119
|
+
Fix misspelled options, and send fields the library does not model with
|
|
120
|
+
`extra_body_parameters:`.
|
|
121
|
+
```ruby
|
|
122
|
+
client.translate_text('Hello', 'EN', 'DE', extra_body_parameters: { new_field: 'value' })
|
|
123
|
+
```
|
|
124
|
+
- `translate_text` and `rephrase_text` raise `ArgumentError` for an empty text (an empty string,
|
|
125
|
+
an empty array, or an array containing an empty string). `rephrase_text` and `correct_text`
|
|
126
|
+
raise it for `target_lang: ''`; `nil` still keeps the language of the text.
|
|
127
|
+
- `translate_text`, `translate_document` and `translate_document_upload` raise `ArgumentError`
|
|
128
|
+
for an empty or `nil` `target_lang`, an empty `source_lang` (pass `nil` to detect it), and a
|
|
129
|
+
`translation_memory_threshold` without `translation_memory` or outside 0 to 100
|
|
130
|
+
(`translate_document` wraps it in `DeepL::Exceptions::DocumentTranslationError`).
|
|
131
|
+
- The same three methods raise `ArgumentError` when `glossary`, `style_rule`, `style_profile` or
|
|
132
|
+
`translation_memory` is an empty ID or a resource object without its ID, or when
|
|
133
|
+
`glossary_ids` has an empty entry or a glossary without its ID (`translate_document` wraps it
|
|
134
|
+
in `DeepL::Exceptions::DocumentTranslationError`). Before, they were sent empty or as `null`.
|
|
135
|
+
`nil` for one of the four options still leaves it unset.
|
|
136
|
+
|
|
137
|
+
## Documents
|
|
138
|
+
|
|
139
|
+
`DeepL.document` and `DeepL::DocumentApi` are removed. Use the `Client` methods.
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
# Before (3.x)
|
|
143
|
+
handle = DeepL.document.upload('in.docx', 'EN', 'DE', 'in.docx')
|
|
144
|
+
DeepL.document.get_status(handle)
|
|
145
|
+
handle.wait_until_document_translation_finished
|
|
146
|
+
DeepL.document.download(handle, 'out.docx')
|
|
147
|
+
|
|
148
|
+
# After
|
|
149
|
+
handle = client.translate_document_upload('in.docx', 'EN', 'DE', filename: 'in.docx')
|
|
150
|
+
status = client.translate_document_wait_until_done(handle)
|
|
151
|
+
client.translate_document_download(handle, 'out.docx')
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
- `translate_document(input, output, source_lang, target_lang)` returns the final
|
|
155
|
+
`DeepL::Resources::DocumentTranslationStatus`, was the number of bytes written.
|
|
156
|
+
- `translate_document_download` returns `nil`.
|
|
157
|
+
- `DocumentHandle#wait_until_document_translation_finished` is removed; use
|
|
158
|
+
`Client#translate_document_wait_until_done`, which raises
|
|
159
|
+
`DeepL::Exceptions::Error` with the API's message if the translation fails or `timeout_s`
|
|
160
|
+
expires.
|
|
161
|
+
- `DocumentTranslationStatus#successful?` is removed; use `#done?`.
|
|
162
|
+
- `translate_document_download` no longer overwrites a file. Before the request it raises
|
|
163
|
+
`Errno::EEXIST` if `output_path` exists, and `Errno::ENOENT` or `Errno::EACCES` if its
|
|
164
|
+
directory is missing or not writable. Delete the old file first.
|
|
165
|
+
- `translate_document` checks the output path before uploading, so a bad path fails at once
|
|
166
|
+
instead of after the translation. It raises `DeepL::Exceptions::DocumentTranslationError`
|
|
167
|
+
(`document_handle` is `nil`) for an existing output file and for a directory that is missing
|
|
168
|
+
or not writable (the `SystemCallError` is its `cause`), and for an invalid upload argument,
|
|
169
|
+
such as an unknown option (the `ArgumentError` is its `cause`). A missing input file raises
|
|
170
|
+
`ArgumentError`, as `Client#translate_document` did in 3.10.0;
|
|
171
|
+
`DeepL.document.translate_document` raised `DeepL::Exceptions::DocumentTranslationError`.
|
|
172
|
+
- `translate_document_upload` raises `Errno::EISDIR` before any request if `input_path` is a
|
|
173
|
+
directory (`translate_document` wraps it in `DeepL::Exceptions::DocumentTranslationError`);
|
|
174
|
+
before, it raised `DeepL::Exceptions::ConnectionError`. Rescue `SystemCallError` for unreadable
|
|
175
|
+
input paths.
|
|
176
|
+
- The `glossary` option of document translation requires `source_lang`.
|
|
177
|
+
- A `nil` value in `extra_body_parameters` now removes that form field; before, it was sent
|
|
178
|
+
empty.
|
|
179
|
+
|
|
180
|
+
## Glossaries
|
|
181
|
+
|
|
182
|
+
`DeepL.glossaries` and `DeepL::GlossaryApi` are removed. `DeepL::Client` has the v2 glossary
|
|
183
|
+
methods; for new code, prefer the multilingual glossary methods.
|
|
184
|
+
|
|
185
|
+
```ruby
|
|
186
|
+
# Before (3.x)
|
|
187
|
+
glossary = DeepL.glossaries.create('My glossary', 'EN', 'DE', [%w[hello hallo]])
|
|
188
|
+
DeepL.glossaries.entries(glossary.id)
|
|
189
|
+
DeepL.glossaries.destroy(glossary.id)
|
|
190
|
+
|
|
191
|
+
# After
|
|
192
|
+
glossary = client.create_glossary('My glossary', 'EN', 'DE', { 'hello' => 'hallo' })
|
|
193
|
+
client.get_glossary_entries(glossary) # Hash of source term => target term
|
|
194
|
+
client.delete_glossary(glossary) # returns nil
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
| Removed | Use |
|
|
198
|
+
| ------- | --- |
|
|
199
|
+
| `DeepL.glossaries.create` | `create_glossary` (entries as a Hash), `create_glossary_from_csv` |
|
|
200
|
+
| `.list`, `.find` | `list_glossaries`, `get_glossary` |
|
|
201
|
+
| `.entries` (pairs) | `get_glossary_entries` (Hash) |
|
|
202
|
+
| `.destroy` (returned the ID) | `delete_glossary` (returns `nil`) |
|
|
203
|
+
| `.language_pairs` | `get_glossary_languages` |
|
|
204
|
+
|
|
205
|
+
The multilingual glossary and spoken terms methods raise `ArgumentError` before any request for
|
|
206
|
+
an empty ID, a glossary or spoken terms object without an ID, an empty name, an empty
|
|
207
|
+
`source_lang` or `target_lang` of `delete_multilingual_glossary_dictionary`, an empty
|
|
208
|
+
`dictionaries` array, and dictionary entries or CSV content that are empty. The multilingual
|
|
209
|
+
glossary methods that take a dictionary and `get_multilingual_glossary_dictionary_entries` raise
|
|
210
|
+
it for a `nil` or empty `source_lang` or `target_lang`, and the spoken terms methods that take a
|
|
211
|
+
language for a `nil` or empty `lang`; before, the request was sent and the API rejected it.
|
|
212
|
+
|
|
213
|
+
`get_multilingual_glossary_dictionary_entries` raises `DeepL::Exceptions::NotFound` if the
|
|
214
|
+
glossary has no dictionary for the language pair. The API answers that with HTTP 404, and the
|
|
215
|
+
error has status 404 and the response. If the API answers 200 with no entries instead, the error
|
|
216
|
+
now has `http_status_code` `nil` and `response` `nil`; before, it carried status 200 and that
|
|
217
|
+
response. Check the error class, not the status.
|
|
218
|
+
|
|
219
|
+
## Style rules
|
|
220
|
+
|
|
221
|
+
`DeepL.style_rules` and `DeepL::StyleRuleApi` are removed.
|
|
222
|
+
|
|
223
|
+
```ruby
|
|
224
|
+
# Before (3.x)
|
|
225
|
+
rule = DeepL.style_rules.find(rule_id)
|
|
226
|
+
rule.configured_rules.numbers
|
|
227
|
+
|
|
228
|
+
# After
|
|
229
|
+
rule = client.get_style_rule(rule_id)
|
|
230
|
+
rule.configured_rules.fetch('numbers', {})
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
- Use `get_all_style_rules`, `create_style_rule` and the other style rule methods of
|
|
234
|
+
`DeepL::Client`. They take `source_language:` as a keyword, and the delete methods return
|
|
235
|
+
`nil`.
|
|
236
|
+
- `StyleRule#configured_rules` is a Hash with string keys (category, rule, value), as the API
|
|
237
|
+
sends it, not a `ConfiguredRules` object. `DeepL::Resources::ConfiguredRules` is removed.
|
|
238
|
+
Absent categories are no longer filled with `{}`.
|
|
239
|
+
- The style rule methods raise `ArgumentError` before any request for an empty ID, a style rule
|
|
240
|
+
or custom instruction without an ID, and an empty name, language, label or prompt. An empty
|
|
241
|
+
`source_language` of `create_style_rule_custom_instruction`,
|
|
242
|
+
`update_style_rule_custom_instruction` or the `custom_instructions` of `create_style_rule`
|
|
243
|
+
raises it too; `nil` still leaves it out.
|
|
244
|
+
|
|
245
|
+
## Translation memories
|
|
246
|
+
|
|
247
|
+
`DeepL.translation_memories` and `DeepL::TranslationMemoryApi` are removed. Use the translation
|
|
248
|
+
memory methods of `DeepL::Client` (`list_translation_memories`, ...).
|
|
249
|
+
A non-2xx reply of the upload or download URL raises `DeepL::Exceptions::Error` with
|
|
250
|
+
`http_status_code`.
|
|
251
|
+
|
|
252
|
+
- `create_translation_memory_import` and `import_translation_memory_from_filepath` take
|
|
253
|
+
`extra_body_parameters:` instead of `**options`; any other option raises `ArgumentError`.
|
|
254
|
+
```ruby
|
|
255
|
+
client.import_translation_memory_from_filepath('tm.tmx', extra_body_parameters: { key: 'value' })
|
|
256
|
+
```
|
|
257
|
+
- `download_translation_memory_export(job, output_path)` takes a
|
|
258
|
+
`DeepL::Resources::TranslationMemoryJob` instead of a download URL string. Pass the job
|
|
259
|
+
returned by `wait_until_translation_memory_job_done`.
|
|
260
|
+
```ruby
|
|
261
|
+
# Before
|
|
262
|
+
client.download_translation_memory_export(job.result.download_url, 'out.tmx')
|
|
263
|
+
# After
|
|
264
|
+
client.download_translation_memory_export(job, 'out.tmx')
|
|
265
|
+
```
|
|
266
|
+
- `download_translation_memory_export` and `export_translation_memory_to_filepath` no longer
|
|
267
|
+
overwrite an existing file. The first raises `Errno::EEXIST`, `Errno::ENOENT` or
|
|
268
|
+
`Errno::EACCES` before the request, and a write failure raises the `Errno` error, so rescue
|
|
269
|
+
`SystemCallError`, not only `DeepL::Exceptions::Error`.
|
|
270
|
+
- `import_translation_memory_from_filepath` and `export_translation_memory_to_filepath` wrap
|
|
271
|
+
every failure except a missing input file in the new
|
|
272
|
+
`DeepL::Exceptions::TranslationMemoryJobError` (a `DeepL::Exceptions::Error`), with the
|
|
273
|
+
original error as `cause`, plus `job_id` and `job`. An empty input file raises it too; before,
|
|
274
|
+
it raised `ArgumentError`.
|
|
275
|
+
- Methods raise `ArgumentError` instead of `DeepL::Exceptions::Error` for an empty translation
|
|
276
|
+
memory ID or job ID and an empty upload URL. An export job with an empty or no download URL
|
|
277
|
+
still raises `DeepL::Exceptions::Error`. `create_translation_memory_import` also rejects an
|
|
278
|
+
empty `file_name` and a `content_length` that is not positive.
|
|
279
|
+
- `TranslationMemoryJobResult::STATUS_DOWNLOADED` is removed (the API never sends it); use
|
|
280
|
+
`STATUS_COMPLETED` or `done?`. `TranslationMemoryJob#finished?` is `false` for `downloaded`.
|
|
281
|
+
- `create_translation_memory_export` sends no request body (`Content-Length: 0`).
|
|
282
|
+
|
|
283
|
+
## Usage
|
|
284
|
+
|
|
285
|
+
`DeepL.usage` is replaced by `Client#get_usage`. The character counters moved into
|
|
286
|
+
`usage.character`.
|
|
287
|
+
|
|
288
|
+
```ruby
|
|
289
|
+
# Before (3.x)
|
|
290
|
+
usage = DeepL.usage
|
|
291
|
+
usage.character_count
|
|
292
|
+
usage.character_limit
|
|
293
|
+
usage.quota_exceeded?
|
|
294
|
+
usage.any_limit_reached?
|
|
295
|
+
|
|
296
|
+
# After
|
|
297
|
+
usage = client.get_usage
|
|
298
|
+
usage.character.count
|
|
299
|
+
usage.character.limit
|
|
300
|
+
usage.character.limit_reached?
|
|
301
|
+
usage.any_character_limit_reached?
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
- `any_character_limit_reached?` is `true` if the account's `character` limit or this API key's
|
|
305
|
+
`api_key_character` limit is reached. The speech minutes are not considered; check them with
|
|
306
|
+
`limit_reached?` on the detail.
|
|
307
|
+
- `Usage#document` and `Usage#team_document` are removed; the API no longer returns them.
|
|
308
|
+
|
|
309
|
+
## Errors, validation and retries
|
|
310
|
+
|
|
311
|
+
- **Network failures** always raise `DeepL::Exceptions::ConnectionError`, with the original
|
|
312
|
+
error as `cause`. The removed module-level API raised the original error.
|
|
313
|
+
```ruby
|
|
314
|
+
begin
|
|
315
|
+
client.get_usage
|
|
316
|
+
rescue DeepL::Exceptions::ConnectionError => e
|
|
317
|
+
warn e.cause.class
|
|
318
|
+
end
|
|
319
|
+
```
|
|
320
|
+
- **`DeepL::Exceptions::ValidationError` is an `ArgumentError`**, no longer a
|
|
321
|
+
`DeepL::Exceptions::Error`. `rescue DeepL::Exceptions::Error` does not catch it; rescue
|
|
322
|
+
`ArgumentError` to catch every invalid argument.
|
|
323
|
+
- **`DeepL::Exceptions::NotSupported`** is removed; nothing raises it.
|
|
324
|
+
- **Retries of calls that create a resource.** `create_glossary`, `create_glossary_from_csv`,
|
|
325
|
+
`create_multilingual_glossary`, `create_multilingual_glossary_from_csv`, `create_spoken_terms`,
|
|
326
|
+
`create_style_rule`, `create_style_rule_custom_instruction`, `create_style_profile`, the
|
|
327
|
+
document upload, and the translation memory import and export job creation are retried only
|
|
328
|
+
when the request cannot have been processed: after HTTP 429 and transient network failures
|
|
329
|
+
while connecting, before the request is sent, such as DNS resolution errors, refused
|
|
330
|
+
connections, unreachable hosts or networks, connection timeouts and resets during the TLS or
|
|
331
|
+
proxy handshake. A 5xx reply raises `DeepL::Exceptions::ServerError` with `should_retry?`
|
|
332
|
+
`false` at once. If you retry these calls yourself, check first whether the resource was
|
|
333
|
+
created.
|
|
334
|
+
- `AdminClient#create_developer_key` is retried after the same connect failures. Before, it was
|
|
335
|
+
retried only after DNS resolution errors, refused connections and connection timeouts, and
|
|
336
|
+
raised `ConnectionError` at once for the others. Code that retries it itself now sees the
|
|
337
|
+
library's retries first.
|
|
338
|
+
- A response that fails after its headers arrived on such a request, `create_developer_key`
|
|
339
|
+
included, is not retried and raises `ConnectionError` with `should_retry?` `true` (body cut off
|
|
340
|
+
before its `Content-Length`, reset or read timeout). In 3.10.0 `create_developer_key` raised it
|
|
341
|
+
with `should_retry?` `false` and the other create requests retried it. A connection closed
|
|
342
|
+
before the response now has `should_retry?` `false`. Check first whether the resource was
|
|
343
|
+
created.
|
|
344
|
+
- **Messages** of `AuthorizationFailed`, `RequestEntityTooLarge`, `LimitExceeded`,
|
|
345
|
+
`QuotaExceeded` and `ServerError` now end with `: <API message>`, which replaces the final
|
|
346
|
+
period of the fixed text. Check the error class, not the message.
|
|
347
|
+
- `Language#supports_formality?` returns `nil` for a source language; for a source language of
|
|
348
|
+
the removed `DeepL.languages` it raised `NotSupported`. `DeepL.languages` is removed; use
|
|
349
|
+
`client.get_source_languages` or `client.get_target_languages`.
|
|
350
|
+
|
|
351
|
+
## Types and signatures
|
|
352
|
+
|
|
353
|
+
- `AdminClient#set_developer_key_usage_limits` accepts only `characters:`,
|
|
354
|
+
`speech_to_text_milliseconds:` and `speech_to_speech_milliseconds:`; any other keyword raises
|
|
355
|
+
`ArgumentError`. Send other fields with `extra_body_parameters:`.
|
|
356
|
+
- Argument types are no longer checked by hand. `app_info:` of a type other than
|
|
357
|
+
`DeepL::AppInfo` or a Hash no longer raises `ArgumentError`, and a glossary entry whose terms
|
|
358
|
+
are not strings (for example `{ 'a' => 1 }`) no longer raises
|
|
359
|
+
`DeepL::Exceptions::ValidationError`; such a value fails as Ruby fails or is sent as its string
|
|
360
|
+
form. Value checks are unchanged. Pass the documented types.
|
|
361
|
+
- `Client#translate_document_download`, `#delete_glossary` and the style rule delete methods
|
|
362
|
+
return `nil`.
|
|
363
|
+
|
|
364
|
+
## Internal classes
|
|
365
|
+
|
|
366
|
+
These classes were reachable but are not part of the public API. They changed or were removed:
|
|
367
|
+
|
|
368
|
+
- `DeepL::DocumentApi`, `DeepL::GlossaryApi`, `DeepL::StyleRuleApi`, `DeepL::TranslationMemoryApi`:
|
|
369
|
+
removed; their logic lives in `DeepL::Client`.
|
|
370
|
+
- `DeepL::Configuration`: no longer public; the setters are removed.
|
|
371
|
+
- `DeepL::API`: now holds the configuration and connection of one client; `#client?` and
|
|
372
|
+
`#update_http_client` are removed.
|
|
373
|
+
- `DeepL::Deprecation`: removed.
|
|
374
|
+
- `DeepL::Resources::ConfiguredRules`: removed.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: deepl-rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- DeepL SE
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: juwelier
|
|
@@ -61,7 +61,6 @@ extra_rdoc_files:
|
|
|
61
61
|
- LICENSE.md
|
|
62
62
|
- README.md
|
|
63
63
|
files:
|
|
64
|
-
- ".gitlab-ci.yml"
|
|
65
64
|
- ".rubocop.yml"
|
|
66
65
|
- CHANGELOG.md
|
|
67
66
|
- CODE_OF_CONDUCT.md
|
|
@@ -92,8 +91,6 @@ files:
|
|
|
92
91
|
- lib/deepl/constants/tag_handling_version.rb
|
|
93
92
|
- lib/deepl/constants/tone.rb
|
|
94
93
|
- lib/deepl/constants/writing_style.rb
|
|
95
|
-
- lib/deepl/deprecation.rb
|
|
96
|
-
- lib/deepl/document_api.rb
|
|
97
94
|
- lib/deepl/exceptions/authorization_failed.rb
|
|
98
95
|
- lib/deepl/exceptions/bad_request.rb
|
|
99
96
|
- lib/deepl/exceptions/connection_error.rb
|
|
@@ -102,13 +99,12 @@ files:
|
|
|
102
99
|
- lib/deepl/exceptions/error.rb
|
|
103
100
|
- lib/deepl/exceptions/limit_exceeded.rb
|
|
104
101
|
- lib/deepl/exceptions/not_found.rb
|
|
105
|
-
- lib/deepl/exceptions/not_supported.rb
|
|
106
102
|
- lib/deepl/exceptions/quota_exceeded.rb
|
|
107
103
|
- lib/deepl/exceptions/request_entity_too_large.rb
|
|
108
104
|
- lib/deepl/exceptions/request_error.rb
|
|
109
105
|
- lib/deepl/exceptions/server_error.rb
|
|
106
|
+
- lib/deepl/exceptions/translation_memory_job_error.rb
|
|
110
107
|
- lib/deepl/exceptions/validation_error.rb
|
|
111
|
-
- lib/deepl/glossary_api.rb
|
|
112
108
|
- lib/deepl/requests/admin/base.rb
|
|
113
109
|
- lib/deepl/requests/admin/create_developer_key.rb
|
|
114
110
|
- lib/deepl/requests/admin/custom_tag_usage_analytics.rb
|
|
@@ -120,6 +116,7 @@ files:
|
|
|
120
116
|
- lib/deepl/requests/document/download.rb
|
|
121
117
|
- lib/deepl/requests/document/get_status.rb
|
|
122
118
|
- lib/deepl/requests/document/upload.rb
|
|
119
|
+
- lib/deepl/requests/glossary/base.rb
|
|
123
120
|
- lib/deepl/requests/glossary/create.rb
|
|
124
121
|
- lib/deepl/requests/glossary/destroy.rb
|
|
125
122
|
- lib/deepl/requests/glossary/entries.rb
|
|
@@ -201,58 +198,20 @@ files:
|
|
|
201
198
|
- lib/deepl/resources/translation_memory_job.rb
|
|
202
199
|
- lib/deepl/resources/translation_memory_segments.rb
|
|
203
200
|
- lib/deepl/resources/usage.rb
|
|
204
|
-
- lib/deepl/style_rule_api.rb
|
|
205
|
-
- lib/deepl/translation_memory_api.rb
|
|
206
201
|
- lib/deepl/utils/backoff_timer.rb
|
|
207
202
|
- lib/deepl/utils/client_builder.rb
|
|
208
203
|
- lib/deepl/utils/document_poller.rb
|
|
209
204
|
- lib/deepl/utils/exception_builder.rb
|
|
205
|
+
- lib/deepl/utils/glossary_entries.rb
|
|
210
206
|
- lib/deepl/utils/http_client_builder.rb
|
|
211
207
|
- lib/deepl/utils/number_parser.rb
|
|
208
|
+
- lib/deepl/utils/output_path.rb
|
|
212
209
|
- lib/deepl/utils/term_validator.rb
|
|
213
210
|
- lib/deepl/utils/time_parser.rb
|
|
211
|
+
- lib/deepl/utils/translation_memory_operations.rb
|
|
214
212
|
- lib/http_client_options.rb
|
|
215
213
|
- lib/version.rb
|
|
216
|
-
-
|
|
217
|
-
- spec/fixtures.rb
|
|
218
|
-
- spec/offline/admin_client_spec.rb
|
|
219
|
-
- spec/offline/client_spec.rb
|
|
220
|
-
- spec/offline/configuration_spec.rb
|
|
221
|
-
- spec/offline/constants_spec.rb
|
|
222
|
-
- spec/offline/correct_text_spec.rb
|
|
223
|
-
- spec/offline/deprecation_spec.rb
|
|
224
|
-
- spec/offline/errors_spec.rb
|
|
225
|
-
- spec/offline/glossaries_spec.rb
|
|
226
|
-
- spec/offline/http_client_spec.rb
|
|
227
|
-
- spec/offline/languages_spec.rb
|
|
228
|
-
- spec/offline/module_methods_spec.rb
|
|
229
|
-
- spec/offline/multilingual_glossaries_spec.rb
|
|
230
|
-
- spec/offline/offline_helper.rb
|
|
231
|
-
- spec/offline/rephrase_text_spec.rb
|
|
232
|
-
- spec/offline/spoken_terms_spec.rb
|
|
233
|
-
- spec/offline/style_profiles_spec.rb
|
|
234
|
-
- spec/offline/style_rules_spec.rb
|
|
235
|
-
- spec/offline/translate_document_spec.rb
|
|
236
|
-
- spec/offline/translate_text_spec.rb
|
|
237
|
-
- spec/offline/translation_memories_client_spec.rb
|
|
238
|
-
- spec/offline/translation_memories_spec.rb
|
|
239
|
-
- spec/offline/usage_spec.rb
|
|
240
|
-
- spec/real_api/admin_client_spec.rb
|
|
241
|
-
- spec/real_api/correct_text_spec.rb
|
|
242
|
-
- spec/real_api/glossaries_spec.rb
|
|
243
|
-
- spec/real_api/languages_spec.rb
|
|
244
|
-
- spec/real_api/multilingual_glossaries_spec.rb
|
|
245
|
-
- spec/real_api/proxy_spec.rb
|
|
246
|
-
- spec/real_api/real_api_helper.rb
|
|
247
|
-
- spec/real_api/rephrase_text_spec.rb
|
|
248
|
-
- spec/real_api/spoken_terms_spec.rb
|
|
249
|
-
- spec/real_api/style_profiles_spec.rb
|
|
250
|
-
- spec/real_api/style_rules_spec.rb
|
|
251
|
-
- spec/real_api/translate_document_spec.rb
|
|
252
|
-
- spec/real_api/translate_text_spec.rb
|
|
253
|
-
- spec/real_api/translation_memories_spec.rb
|
|
254
|
-
- spec/real_api/usage_spec.rb
|
|
255
|
-
- spec/spec_helper.rb
|
|
214
|
+
- upgrading_to_v4.md
|
|
256
215
|
homepage: https://github.com/DeepLcom/deepl-rb
|
|
257
216
|
licenses:
|
|
258
217
|
- MIT
|
|
@@ -269,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
269
228
|
requirements:
|
|
270
229
|
- - ">="
|
|
271
230
|
- !ruby/object:Gem::Version
|
|
272
|
-
version: '0'
|
|
231
|
+
version: '3.0'
|
|
273
232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
274
233
|
requirements:
|
|
275
234
|
- - ">="
|