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/README.md
CHANGED
|
@@ -12,6 +12,8 @@ To use the DeepL Ruby Library, you'll need an API authentication key. To get a k
|
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
15
|
+
Requires Ruby 3.0 and later.
|
|
16
|
+
|
|
15
17
|
Install this gem with
|
|
16
18
|
|
|
17
19
|
```sh
|
|
@@ -25,6 +27,11 @@ Or add it to your Gemfile:
|
|
|
25
27
|
gem 'deepl-rb', require: 'deepl'
|
|
26
28
|
```
|
|
27
29
|
|
|
30
|
+
### Upgrading
|
|
31
|
+
|
|
32
|
+
Upgrading from version 3? Read [Upgrading to 4.0.0](upgrading_to_v4.md) for the removed
|
|
33
|
+
module-level API, the stricter argument checks and the other breaking changes.
|
|
34
|
+
|
|
28
35
|
## Usage
|
|
29
36
|
|
|
30
37
|
### Creating a client
|
|
@@ -41,16 +48,17 @@ client = DeepL::Client.new(ENV.fetch('DEEPL_AUTH_KEY'))
|
|
|
41
48
|
|
|
42
49
|
| Option | Default | Description |
|
|
43
50
|
| ------ | ------- | ----------- |
|
|
44
|
-
| `server_url:` | `https://api-free.deepl.com` for Free keys (ending in `:fx`), else `https://api.deepl.com` | Base URL of the DeepL API. A path prefix
|
|
51
|
+
| `server_url:` | `https://api-free.deepl.com` for Free keys (ending in `:fx`), else `https://api.deepl.com` | Base URL of the DeepL API: an absolute `http` or `https` URL with a host. A port and a path prefix are kept, trailing slashes are removed. Any other value raises `ArgumentError`. |
|
|
45
52
|
| `headers:` | `{}` | HTTP headers sent with every DeepL API request. A header of the same name, in any casing, replaces the library's, `Authorization` and `User-Agent` included, except `Content-Type`, `Content-Length`, `Transfer-Encoding` and `Host`. Pre-signed storage URLs get only the `User-Agent`. |
|
|
46
|
-
| `max_retries:` | `5` | Retries after the first attempt, for HTTP 429, any 5xx and transient network failures. |
|
|
53
|
+
| `max_retries:` | `5` | Retries after the first attempt, for HTTP 429, any 5xx and transient network failures. Requests that create a resource (glossaries, spoken terms, style rule lists and custom instructions, style profiles, document uploads, translation memory import and export jobs) are retried only after HTTP 429 and transient network failures while connecting, such as DNS resolution errors, refused connections, unreachable hosts or networks, connection timeouts and resets during the TLS or proxy handshake, when the API cannot have processed them, so that a retry cannot create a second resource. |
|
|
47
54
|
| `timeout:` | `10` | Timeout of each attempt in seconds. A longer backoff interval takes precedence. |
|
|
48
|
-
| `proxy:` | none | Proxy URL
|
|
55
|
+
| `proxy:` | none | Proxy URL (`http://` or `https://`) as a String or `URI`, e.g. `http://user:password@proxy.example:8080`, or a hash with `proxy_addr` and `proxy_port`. Any other value raises `ArgumentError`. |
|
|
49
56
|
| `send_platform_info:` | `true` | Adds the OS and Ruby versions to the `User-Agent`. |
|
|
50
57
|
| `app_info:` | none | A `DeepL::AppInfo` or a hash with `app_name` and `app_version`, added to the `User-Agent`. |
|
|
51
58
|
| `http_client_options:` | none | A `DeepL::HTTPClientOptions` with proxy, certificate, SSL verification and per-phase timeouts. Its timeouts take precedence over `timeout:`. |
|
|
52
59
|
| `logger:` | none | Logger for requests and retries, see [Logging](#logging). |
|
|
53
60
|
|
|
61
|
+
A keyword argument given as `nil` takes its default, like an omitted one.
|
|
54
62
|
The authentication key is trimmed; an empty key raises `ArgumentError`.
|
|
55
63
|
`DeepL::Client.free_account_auth_key?(key)` returns whether a key is a DeepL API Free key.
|
|
56
64
|
|
|
@@ -58,71 +66,42 @@ The authentication key is trimmed; an empty key raises `ArgumentError`.
|
|
|
58
66
|
document translation (`translate_document` and its steps, see
|
|
59
67
|
[Translate documents](#translate-documents)), rephrasing and correction (`rephrase_text` and
|
|
60
68
|
`correct_text`, see [Rephrase Text](#rephrase-text) and [Correct Text](#correct-text)),
|
|
61
|
-
|
|
69
|
+
glossaries (see [Glossaries](#glossaries) and [Multilingual glossaries](#multilingual-glossaries)),
|
|
62
70
|
spoken terms (see
|
|
63
|
-
[Spoken terms](#spoken-terms))
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
### Module-level configuration (deprecated)
|
|
69
|
-
|
|
70
|
-
Setup an environment variable named `DEEPL_AUTH_KEY` with your authentication key:
|
|
71
|
-
|
|
72
|
-
```sh
|
|
73
|
-
export DEEPL_AUTH_KEY="your-api-token"
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Alternatively, you can configure the API client within a ruby block:
|
|
77
|
-
|
|
78
|
-
```rb
|
|
79
|
-
DeepL.configure do |config|
|
|
80
|
-
config.auth_key = 'your-api-token'
|
|
81
|
-
end
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
You can also configure the API host and the API version:
|
|
85
|
-
|
|
86
|
-
```rb
|
|
87
|
-
DeepL.configure do |config|
|
|
88
|
-
config.auth_key = 'your-api-token'
|
|
89
|
-
config.host = 'https://api-free.deepl.com' # Default value is 'https://api.deepl.com'
|
|
90
|
-
end
|
|
91
|
-
```
|
|
71
|
+
[Spoken terms](#spoken-terms)), style rules (see [Style Rules](#style-rules)), style profiles
|
|
72
|
+
(see [Style profiles](#style-profiles)), translation memories (see
|
|
73
|
+
[Translation Memories](#translation-memories)) and usage (`get_usage`, see
|
|
74
|
+
[Monitor usage](#monitor-usage)).
|
|
92
75
|
|
|
93
|
-
|
|
94
|
-
|
|
76
|
+
The module-level API of version 3 (`DeepL.configure`, `DeepL.translate`, `DeepL.glossaries`,
|
|
77
|
+
...) has been removed, see [Migrating from the module-level API](#migrating-from-the-module-level-api).
|
|
95
78
|
|
|
96
|
-
### Migrating
|
|
79
|
+
### Migrating from the module-level API
|
|
97
80
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
`Warning[:deprecated] = true`). The `DeepL::Client` methods replacing it:
|
|
81
|
+
Version 4 removes the module-level API of version 3, deprecated in 3.10.0. Create a
|
|
82
|
+
`DeepL::Client` and call its methods instead:
|
|
101
83
|
|
|
102
|
-
| Module-level API | `DeepL::Client` |
|
|
103
|
-
|
|
|
104
|
-
| `DeepL.configure` | `DeepL::Client.new(
|
|
84
|
+
| Module-level API (removed) | `DeepL::Client` |
|
|
85
|
+
| -------------------------- | --------------- |
|
|
86
|
+
| `DeepL.configure`, `DeepL.configuration` | `DeepL::Client.new(auth_key, server_url:, headers:, max_retries:, timeout:, ...)` |
|
|
105
87
|
| `DeepL.translate` | `translate_text` |
|
|
106
|
-
| `DeepL.rephrase` | `rephrase_text` |
|
|
88
|
+
| `DeepL.rephrase` | `rephrase_text` (`writing_style:` and `tone:` are keywords) |
|
|
107
89
|
| `DeepL.usage` | `get_usage` |
|
|
108
90
|
| `DeepL.languages(type:)` | `get_source_languages` / `get_target_languages` |
|
|
109
91
|
| `DeepL.document.*` | `translate_document`, `translate_document_upload`, `translate_document_get_status`, `translate_document_wait_until_done`, `translate_document_download` |
|
|
110
|
-
| `DeepL.glossaries` |
|
|
92
|
+
| `DeepL.glossaries` | `create_glossary`, `create_glossary_from_csv`, `list_glossaries`, `get_glossary`, `get_glossary_entries`, `delete_glossary`, `get_glossary_languages` |
|
|
111
93
|
| `DeepL.style_rules` | the style rule methods (`get_all_style_rules`, `create_style_rule`, ...) |
|
|
112
94
|
| `DeepL.translation_memories` | the translation memory methods (`list_translation_memories`, ...) |
|
|
113
|
-
| `DeepL.with_session
|
|
95
|
+
| `DeepL.with_session`, `DeepL.http_client`, `DeepL.api` | the `proxy:` and `http_client_options:` options |
|
|
114
96
|
| per-call `additional_headers` | the `headers:` option |
|
|
97
|
+
| `config.user_agent` | `app_info:`, `send_platform_info:` or a `User-Agent` in `headers:` |
|
|
115
98
|
|
|
116
|
-
`DeepL::Client`
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
module-level `DeepL.document.translate_document` returns the number of bytes written).
|
|
123
|
-
- The translation memory file helpers raise `ArgumentError` for a missing input file and
|
|
124
|
-
`DeepL::Exceptions::Error` for other local file failures (the module-level API raises
|
|
125
|
-
`DeepL::Exceptions::Error` and the raw `Errno::*`).
|
|
99
|
+
`DeepL::Client` reads no environment variables: pass the key (and the server URL, if needed)
|
|
100
|
+
yourself. Its behaviour differs from the removed API: network failures raise
|
|
101
|
+
`DeepL::Exceptions::ConnectionError` with the original error as `cause`; the timeout of each
|
|
102
|
+
attempt defaults to 10 seconds instead of 60; an array of texts always returns an array;
|
|
103
|
+
`translate_document` returns the final status; the delete methods return `nil`; and
|
|
104
|
+
`supports_formality?` returns `nil` for a source language instead of raising.
|
|
126
105
|
|
|
127
106
|
### Available languages
|
|
128
107
|
|
|
@@ -143,15 +122,10 @@ puts german.supports_formality?
|
|
|
143
122
|
```
|
|
144
123
|
|
|
145
124
|
`supports_formality?` is `true` or `false` for target languages and `nil` for source languages.
|
|
146
|
-
For a source language of the module-level `DeepL.languages`, it raises
|
|
147
|
-
`DeepL::Exceptions::NotSupported`, as in version 3.9.0.
|
|
148
125
|
|
|
149
126
|
All languages are also defined on the
|
|
150
127
|
[official API documentation](https://developers.deepl.com/docs/api-reference/translate).
|
|
151
128
|
|
|
152
|
-
The module-level `DeepL.languages(type: :source)` and `DeepL.languages(type: :target)` are
|
|
153
|
-
deprecated.
|
|
154
|
-
|
|
155
129
|
#### Languages per resource
|
|
156
130
|
|
|
157
131
|
`get_languages_for_resource` returns the languages supported by a given API resource, with
|
|
@@ -210,6 +184,10 @@ billed for the text; the library always asks the API for it), `model_type_used`
|
|
|
210
184
|
`tag_handling_version` (the tag handling version the API used, when tag handling was
|
|
211
185
|
requested). A field the response does not contain is `nil`.
|
|
212
186
|
|
|
187
|
+
An empty text (an empty string, an empty array or an array with an empty string), an empty
|
|
188
|
+
`target_lang` and an empty `source_lang` (pass `nil` to detect the source language) raise
|
|
189
|
+
`ArgumentError` before anything is sent.
|
|
190
|
+
|
|
213
191
|
Enable auto-detect source language by skipping the source language with `nil`:
|
|
214
192
|
|
|
215
193
|
```rb
|
|
@@ -312,22 +290,23 @@ The following parameters will be automatically converted:
|
|
|
312
290
|
| `non_splitting_tags` | Converts arrays to strings joining by commas
|
|
313
291
|
| `ignore_tags` | Converts arrays to strings joining by commas
|
|
314
292
|
| `formality` | No conversion applied
|
|
315
|
-
| `glossary` | A glossary ID string, a `Glossary` or a `MultilingualGlossary` object, sent as `glossary_id` (see [Glossaries](#glossaries))
|
|
316
|
-
| `
|
|
317
|
-
| `
|
|
318
|
-
| `
|
|
319
|
-
| `
|
|
320
|
-
| `translation_memory_threshold` | No conversion applied (integer 0-100, recommended minimum 75)
|
|
293
|
+
| `glossary` | A glossary ID string, a `Glossary` or a `MultilingualGlossary` object, sent as `glossary_id` (see [Glossaries](#glossaries)); an empty ID or an object without its ID raises `ArgumentError`
|
|
294
|
+
| `style_rule` | No conversion applied (can be a string ID or a StyleRule object); an empty ID or an object without its ID raises `ArgumentError`
|
|
295
|
+
| `style_profile` | No conversion applied (can be a string ID or a StyleProfile object, see [Style profiles](#style-profiles)); an empty ID or an object without its ID raises `ArgumentError`
|
|
296
|
+
| `translation_memory` | No conversion applied (can be a string ID or a TranslationMemory object); an empty ID or an object without its ID raises `ArgumentError`
|
|
297
|
+
| `translation_memory_threshold` | No conversion applied (integer 0-100, recommended minimum 75); requires `translation_memory`, otherwise `ArgumentError`
|
|
321
298
|
| `context` | No conversion applied
|
|
322
299
|
| `custom_instructions` | An array of strings; a string is sent as a one-element array
|
|
300
|
+
| `tag_handling` | No conversion applied (`DeepL::Constants::TagHandling`)
|
|
323
301
|
| `tag_handling_version` | No conversion applied (`DeepL::Constants::TagHandlingVersion`)
|
|
302
|
+
| `model_type` | No conversion applied (`DeepL::Constants::ModelType`)
|
|
324
303
|
| `extra_body_parameters` | Hash of extra parameters to pass in the body of the HTTP request. Can be used to access beta features, or to override built-in parameters for testing purposes. Extra parameters can override keys explicitly set by the client.
|
|
325
304
|
|
|
326
305
|
`show_billed_characters: true` is always sent.
|
|
327
306
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
307
|
+
Every method accepts only the options it documents. Any other option, also a misspelled one,
|
|
308
|
+
raises `ArgumentError` naming it before a request is sent. To send a field the library does not
|
|
309
|
+
model, add it to `extra_body_parameters`; every method that takes options accepts it.
|
|
331
310
|
|
|
332
311
|
### Rephrase Text
|
|
333
312
|
|
|
@@ -349,7 +328,7 @@ puts rephrased_text.target_language
|
|
|
349
328
|
|
|
350
329
|
As with `translate_text`, the text can be a string or an array of strings: a string returns a
|
|
351
330
|
`DeepL::Resources::Text`, an array returns an array of them (also for an array with one
|
|
352
|
-
element). The target language is optional.
|
|
331
|
+
element). The target language is optional. Empty text raises `ArgumentError`.
|
|
353
332
|
|
|
354
333
|
Use the `writing_style:` or `tone:` keyword to choose the writing style or tone of the
|
|
355
334
|
rephrased text (`DeepL::Constants::WritingStyle` and `DeepL::Constants::Tone` list the values;
|
|
@@ -372,11 +351,6 @@ puts rephrased_text.text
|
|
|
372
351
|
# => 'You'll get to enjoy new, rephrased text!'
|
|
373
352
|
```
|
|
374
353
|
|
|
375
|
-
The deprecated module-level `DeepL.rephrase(text, target_lang = nil, writing_style = nil,
|
|
376
|
-
tone = nil, options = {}, additional_headers = {})` takes the writing style and tone as
|
|
377
|
-
positional arguments. Unlike `rephrase_text`, it returns a single result for a one-element
|
|
378
|
-
array.
|
|
379
|
-
|
|
380
354
|
### Correct Text
|
|
381
355
|
|
|
382
356
|
To fix grammar, spelling and punctuation, use the `correct_text` method of `DeepL::Client`.
|
|
@@ -397,14 +371,17 @@ array with one element). Empty text raises `ArgumentError`. It raises
|
|
|
397
371
|
|
|
398
372
|
### Glossaries
|
|
399
373
|
|
|
400
|
-
|
|
374
|
+
A v2 glossary holds the entries of one language pair. To create one, call `create_glossary`
|
|
375
|
+
with a name, the source and target languages and the entries, a hash of source term to target
|
|
376
|
+
term (source/target pairs or a TSV string work too). Glossaries are not regional: `EN-GB` is
|
|
377
|
+
sent as `EN`. The entries are sent as TSV; each term is stripped of surrounding whitespace, and
|
|
378
|
+
an empty term, one with a control character or a source term that appears twice raises
|
|
379
|
+
`DeepL::Exceptions::ValidationError`, an `ArgumentError`, before anything is sent. An empty name,
|
|
380
|
+
no entries, or a `nil` or empty `source_lang` or `target_lang` raise `ArgumentError`:
|
|
401
381
|
|
|
402
382
|
```rb
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
['car', 'auto']
|
|
406
|
-
]
|
|
407
|
-
glossary = DeepL.glossaries.create 'Mi Glosario', 'EN', 'ES', entries
|
|
383
|
+
glossary = client.create_glossary('My Glossary', 'EN', 'ES',
|
|
384
|
+
{ 'Hello World' => 'Hola Tierra', 'car' => 'auto' })
|
|
408
385
|
|
|
409
386
|
puts glossary.class
|
|
410
387
|
# => DeepL::Resources::Glossary
|
|
@@ -414,9 +391,32 @@ puts glossary.entry_count
|
|
|
414
391
|
# => 2
|
|
415
392
|
```
|
|
416
393
|
|
|
417
|
-
|
|
394
|
+
`create_glossary_from_csv` creates a glossary from CSV content (a string or an IO), for example
|
|
395
|
+
a file downloaded from the DeepL website; the content is sent as given:
|
|
396
|
+
|
|
397
|
+
```rb
|
|
398
|
+
glossary = client.create_glossary_from_csv('My Glossary', 'EN', 'ES', File.open('entries.csv'))
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Every method that takes a glossary accepts its ID or a `DeepL::Resources::Glossary`:
|
|
402
|
+
|
|
403
|
+
```rb
|
|
404
|
+
client.list_glossaries # => Array of DeepL::Resources::Glossary
|
|
405
|
+
client.get_glossary(glossary) # => DeepL::Resources::Glossary, without the entries
|
|
406
|
+
client.get_glossary_entries(glossary)
|
|
407
|
+
# => {"Hello World"=>"Hola Tierra", "car"=>"auto"}
|
|
408
|
+
client.delete_glossary(glossary) # => nil
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
`get_glossary_languages` returns the language pairs supported by glossaries, as
|
|
412
|
+
`DeepL::Resources::LanguagePair` objects with `source_lang` and `target_lang`. A missing
|
|
413
|
+
glossary raises `DeepL::Exceptions::NotFound`. Glossaries with several language pairs are
|
|
414
|
+
managed with the methods in [Multilingual glossaries](#multilingual-glossaries), which also
|
|
415
|
+
handle v2 glossaries.
|
|
416
|
+
|
|
417
|
+
Glossaries can be used in text and document translation by specifying the
|
|
418
418
|
`glossary` option, a glossary ID or a `Glossary` / `MultilingualGlossary` object. It is sent
|
|
419
|
-
as `glossary_id
|
|
419
|
+
as `glossary_id`:
|
|
420
420
|
|
|
421
421
|
```rb
|
|
422
422
|
translation = client.translate_text 'Hello World', 'EN', 'ES', glossary: 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
|
|
@@ -435,14 +435,15 @@ puts translation.text
|
|
|
435
435
|
```
|
|
436
436
|
|
|
437
437
|
To use more than one glossary at once, specify the `glossary_ids` option with an
|
|
438
|
-
array of up to 5 glossary IDs (as strings
|
|
439
|
-
objects) instead of `glossary`. This works for both text and document
|
|
440
|
-
translation. `glossary_ids` cannot be combined with `glossary
|
|
441
|
-
and raises `ArgumentError` if this rule is violated
|
|
442
|
-
provided
|
|
443
|
-
|
|
438
|
+
array of up to 5 glossary IDs (as strings, `DeepL::Resources::Glossary` or
|
|
439
|
+
`DeepL::Resources::MultilingualGlossary` objects) instead of `glossary`. This works for both text and document
|
|
440
|
+
translation. `glossary_ids` cannot be combined with `glossary`,
|
|
441
|
+
and raises `ArgumentError` if this rule is violated, more than 5 IDs are
|
|
442
|
+
provided, or an entry is an empty ID or a glossary without its ID. For text
|
|
443
|
+
translation, a glossary (`glossary` or `glossary_ids`) can be used without
|
|
444
|
+
`source_lang`: the API detects the source language and uses the
|
|
444
445
|
glossary's dictionary for the detected language pair. Document translation with
|
|
445
|
-
`glossary_ids` requires `source_lang` and raises `ArgumentError` without it:
|
|
446
|
+
`glossary` or `glossary_ids` requires `source_lang` and raises `ArgumentError` without it:
|
|
446
447
|
|
|
447
448
|
```rb
|
|
448
449
|
# Text translation with multiple glossaries
|
|
@@ -451,66 +452,9 @@ translation = client.translate_text 'Hello World', 'EN', 'ES',
|
|
|
451
452
|
'bb59d8g1-1e13-524f-9b17-e6ccg1db8b7f']
|
|
452
453
|
|
|
453
454
|
# Document translation with multiple glossaries
|
|
454
|
-
handle =
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
To list all the glossaries available, use the `glossaries.list` method:
|
|
460
|
-
|
|
461
|
-
```rb
|
|
462
|
-
glossaries = DeepL.glossaries.list
|
|
463
|
-
|
|
464
|
-
puts glossaries.class
|
|
465
|
-
# => Array
|
|
466
|
-
puts glossaries.first.class
|
|
467
|
-
# => DeepL::Resources::Glossary
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
To find an existing glossary, use the `glossaries.find` method:
|
|
471
|
-
|
|
472
|
-
```rb
|
|
473
|
-
glossary = DeepL.glossaries.find 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
|
|
474
|
-
|
|
475
|
-
puts glossary.class
|
|
476
|
-
# => DeepL::Resources::Glossary
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
-
The glossary resource does not include the glossary entries. To list the glossary entries, use the `glossaries.entries` method:
|
|
480
|
-
|
|
481
|
-
```rb
|
|
482
|
-
entries = DeepL.glossaries.entries 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
|
|
483
|
-
|
|
484
|
-
puts entries.class
|
|
485
|
-
# => Array
|
|
486
|
-
puts entries.size
|
|
487
|
-
# => 2
|
|
488
|
-
pp entries.first
|
|
489
|
-
# => ["Hello World", "Hola Tierra"]
|
|
490
|
-
```
|
|
491
|
-
|
|
492
|
-
To delete an existing glossary, use the `glossaries.destroy` method:
|
|
493
|
-
|
|
494
|
-
```rb
|
|
495
|
-
glossary_id = DeepL.glossaries.destroy 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
|
|
496
|
-
|
|
497
|
-
puts glossary_id
|
|
498
|
-
# => aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
You can list all the language pairs supported by glossaries using the `glossaries.language_pairs` method:
|
|
502
|
-
|
|
503
|
-
```rb
|
|
504
|
-
language_pairs = DeepL.glossaries.language_pairs
|
|
505
|
-
|
|
506
|
-
puts language_pairs.class
|
|
507
|
-
# => Array
|
|
508
|
-
puts language_pairs.first.class
|
|
509
|
-
# => DeepL::Resources::LanguagePair
|
|
510
|
-
puts language_pairs.first.source_lang
|
|
511
|
-
# => en
|
|
512
|
-
puts language_pairs.first.target_lang
|
|
513
|
-
# => de
|
|
455
|
+
handle = client.translate_document_upload 'my_document.docx', 'EN', 'ES',
|
|
456
|
+
glossary_ids: ['aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e',
|
|
457
|
+
'bb59d8g1-1e13-524f-9b17-e6ccg1db8b7f']
|
|
514
458
|
```
|
|
515
459
|
|
|
516
460
|
### Multilingual glossaries
|
|
@@ -519,7 +463,10 @@ Multilingual glossaries (v3) group several language-pair dictionaries under one
|
|
|
519
463
|
glossary and are managed through `DeepL::Client`. Every method that takes a
|
|
520
464
|
glossary accepts its ID or a `DeepL::Resources::MultilingualGlossary` object; the
|
|
521
465
|
ID is URL-encoded in the request path. A dictionary's `entries` is a hash of
|
|
522
|
-
source term to target term.
|
|
466
|
+
source term to target term. An empty glossary ID (or a glossary object without
|
|
467
|
+
one), an empty name, an empty language of a dictionary to delete, no dictionaries
|
|
468
|
+
on create, or a dictionary without entries raises
|
|
469
|
+
`ArgumentError` before anything is sent.
|
|
523
470
|
|
|
524
471
|
To create a multilingual glossary, pass a name and one
|
|
525
472
|
`DeepL::Resources::MultilingualGlossaryDictionaryEntries` (or a hash with
|
|
@@ -531,8 +478,9 @@ always sent as TSV, whatever `entries_format` says. Terms not given as CSV are c
|
|
|
531
478
|
glossary terms: each term is stripped of surrounding whitespace, and an empty term,
|
|
532
479
|
one with a control character, a pair or TSV line that is not exactly two terms, or a
|
|
533
480
|
source term that appears twice raises
|
|
534
|
-
`DeepL::Exceptions::ValidationError` before anything is sent.
|
|
535
|
-
|
|
481
|
+
`DeepL::Exceptions::ValidationError` (an `ArgumentError`) before anything is sent. Empty or
|
|
482
|
+
whitespace-only CSV content raises `ArgumentError` before anything is sent; other CSV content is
|
|
483
|
+
sent as given. Further options, such as
|
|
536
484
|
`extra_body_parameters`, are given as additional keywords:
|
|
537
485
|
|
|
538
486
|
```rb
|
|
@@ -569,8 +517,9 @@ List or fetch multilingual glossaries with `list_multilingual_glossaries` and
|
|
|
569
517
|
`get_multilingual_glossary`. The glossary does not include the entries; fetch the
|
|
570
518
|
entries of one language pair with `get_multilingual_glossary_dictionary_entries`,
|
|
571
519
|
which raises `DeepL::Exceptions::NotFound` if the glossary has no dictionary for
|
|
572
|
-
that pair
|
|
573
|
-
|
|
520
|
+
that pair (the API answers 404; if it answers 200 with no entries instead, the
|
|
521
|
+
error's `http_status_code` is `nil`). The returned
|
|
522
|
+
object can be passed to the create, update and replace methods:
|
|
574
523
|
|
|
575
524
|
```rb
|
|
576
525
|
glossaries = client.list_multilingual_glossaries
|
|
@@ -616,14 +565,15 @@ client.delete_multilingual_glossary(glossary)
|
|
|
616
565
|
Spoken terms collections improve the transcription of terms such as product
|
|
617
566
|
names. A collection holds one list of terms per language and is managed through
|
|
618
567
|
`DeepL::Client`. Every method that takes a collection accepts its ID or a
|
|
619
|
-
`DeepL::Resources::SpokenTerms` object
|
|
620
|
-
|
|
568
|
+
`DeepL::Resources::SpokenTerms` object; an empty ID, or an object without one,
|
|
569
|
+
raises `ArgumentError` before anything is sent. A `nil` or empty language does too.
|
|
570
|
+
Terms are passed and returned as arrays of strings.
|
|
621
571
|
|
|
622
572
|
To create a collection, pass a name and one `DeepL::Resources::SpokenTermsEntries`
|
|
623
573
|
(or a hash with `:lang` and `:entries`) per language. Terms are checked like
|
|
624
574
|
glossary terms: each term is stripped of surrounding whitespace and sent stripped,
|
|
625
575
|
and `create_spoken_terms`, `update_spoken_terms` and `replace_spoken_terms_list`
|
|
626
|
-
raise `DeepL::Exceptions::ValidationError` before sending anything if a term is then empty or contains
|
|
576
|
+
raise `DeepL::Exceptions::ValidationError` (an `ArgumentError`) before sending anything if a term is then empty or contains
|
|
627
577
|
a C0 or C1 control character (such as a tab or newline), U+2028 or U+2029.
|
|
628
578
|
Further options, such as `extra_body_parameters`, are given as additional
|
|
629
579
|
keywords:
|
|
@@ -691,7 +641,7 @@ puts term_list.entry_count
|
|
|
691
641
|
To delete the list of one language or the entire collection (both return `nil`):
|
|
692
642
|
|
|
693
643
|
```rb
|
|
694
|
-
client.delete_spoken_terms_list(spoken_terms, '
|
|
644
|
+
client.delete_spoken_terms_list(spoken_terms, 'en')
|
|
695
645
|
client.delete_spoken_terms(spoken_terms)
|
|
696
646
|
```
|
|
697
647
|
|
|
@@ -704,7 +654,10 @@ with your account, each with a user-specified name and a uniquely-assigned ID
|
|
|
704
654
|
`create_style_rule`, `get_style_rule`, `update_style_rule_name`,
|
|
705
655
|
`update_style_rule_configured_rules` and `delete_style_rule`. Every method that
|
|
706
656
|
takes a style rule list accepts its ID string or a `DeepL::Resources::StyleRule`
|
|
707
|
-
object
|
|
657
|
+
object, and every method that takes a custom instruction its ID or a
|
|
658
|
+
`DeepL::Resources::CustomInstruction`. An empty ID (or an object without one), and
|
|
659
|
+
an empty name, language, label or prompt, raise `ArgumentError` before anything is
|
|
660
|
+
sent; so does an empty `source_language` of a custom instruction (`nil` leaves it unset).
|
|
708
661
|
|
|
709
662
|
#### Creating a style rule
|
|
710
663
|
|
|
@@ -756,7 +709,7 @@ style_rules = client.get_all_style_rules(page: 0, page_size: 10)
|
|
|
756
709
|
# List with detailed configuration
|
|
757
710
|
client.get_all_style_rules(detailed: true).each do |rule|
|
|
758
711
|
if rule.configured_rules
|
|
759
|
-
puts " Number formatting: #{rule.configured_rules.numbers.keys.join(', ')}"
|
|
712
|
+
puts " Number formatting: #{rule.configured_rules.fetch('numbers', {}).keys.join(', ')}"
|
|
760
713
|
end
|
|
761
714
|
end
|
|
762
715
|
```
|
|
@@ -778,9 +731,10 @@ updated = client.update_style_rule_configured_rules(
|
|
|
778
731
|
)
|
|
779
732
|
```
|
|
780
733
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
and
|
|
734
|
+
`StyleRule#configured_rules` returns the configured rules as the API sends them: a
|
|
735
|
+
hash of category -> rule -> value with string keys, or `nil` when the response omits
|
|
736
|
+
them. Category and rule names are not validated; the API reference lists the
|
|
737
|
+
supported ones.
|
|
784
738
|
|
|
785
739
|
#### Managing custom instructions
|
|
786
740
|
|
|
@@ -824,11 +778,6 @@ Use `delete_style_rule` to delete a style rule list. It returns `nil`.
|
|
|
824
778
|
client.delete_style_rule('YOUR_STYLE_ID')
|
|
825
779
|
```
|
|
826
780
|
|
|
827
|
-
The deprecated module-level `DeepL.style_rules` (`list`, `create`, `find`,
|
|
828
|
-
`update_name`, `update_configured_rules`, `destroy`, `create_custom_instruction`,
|
|
829
|
-
`find_custom_instruction`, `update_custom_instruction`,
|
|
830
|
-
`destroy_custom_instruction`) keeps working unchanged.
|
|
831
|
-
|
|
832
781
|
#### Using style rules in translations
|
|
833
782
|
|
|
834
783
|
Style rules can be used in `translate_text` by specifying the `style_rule` option
|
|
@@ -945,7 +894,7 @@ Pass the `style_profile` option, a style profile ID string or a `StyleProfile` o
|
|
|
945
894
|
`translate_text`, `translate_document` or `translate_document_upload` to apply the
|
|
946
895
|
profile's glossaries, style rule lists and translation memories. A component that does not
|
|
947
896
|
fit the language pair is left out. The option cannot be combined with `glossary`,
|
|
948
|
-
`
|
|
897
|
+
`glossary_ids`, `style_rule`, `translation_memory`,
|
|
949
898
|
`translation_memory_threshold` or `custom_instructions`; the API rejects such requests.
|
|
950
899
|
|
|
951
900
|
```rb
|
|
@@ -977,7 +926,10 @@ https://www.deepl.com/translation-memory.
|
|
|
977
926
|
and `delete_translation_memory`, plus the single steps of an import or export
|
|
978
927
|
described below. Every method that takes a translation memory accepts either a
|
|
979
928
|
string containing the translation memory ID or a `TranslationMemory` object, and
|
|
980
|
-
every method that takes a job accepts its ID or a `TranslationMemoryJob`.
|
|
929
|
+
every method that takes a job accepts its ID or a `TranslationMemoryJob`. An empty
|
|
930
|
+
ID or upload URL, or an object without one, raises `ArgumentError` before any
|
|
931
|
+
request is sent; an export job without a download URL raises
|
|
932
|
+
`DeepL::Exceptions::Error`.
|
|
981
933
|
|
|
982
934
|
#### Listing translation memories
|
|
983
935
|
|
|
@@ -1071,9 +1023,13 @@ of the newly created translation memory. The optional keywords are
|
|
|
1071
1023
|
`content_type` (the MIME type of the file, declared in the job and sent with the
|
|
1072
1024
|
upload, defaults to `application/xml`), `timeout_s` and `extra_body_parameters`
|
|
1073
1025
|
(fields added to the body of the import job request). It raises an
|
|
1074
|
-
`ArgumentError` before any request if the file does not exist
|
|
1075
|
-
`DeepL::Exceptions::
|
|
1076
|
-
|
|
1026
|
+
`ArgumentError` before any request if the file does not exist. Every other
|
|
1027
|
+
failure raises a `DeepL::Exceptions::TranslationMemoryJobError` with the original
|
|
1028
|
+
error as `cause`: an empty or unreadable file (before any request), a failed job
|
|
1029
|
+
creation or upload, a job that fails or expires (with the API's error message),
|
|
1030
|
+
and an expired `timeout_s`. Its `job_id` is set as soon as the job was created,
|
|
1031
|
+
so you can still query it, and its `job` is the last job status fetched (`nil`
|
|
1032
|
+
before the first status check).
|
|
1077
1033
|
|
|
1078
1034
|
```rb
|
|
1079
1035
|
job = client.import_translation_memory_from_filepath('legal.tmx',
|
|
@@ -1095,7 +1051,8 @@ The three steps can also be performed separately with
|
|
|
1095
1051
|
`wait_until_translation_memory_job_done`, for example to upload a file that is
|
|
1096
1052
|
not available on the local file system. `create_translation_memory_import`
|
|
1097
1053
|
accepts `content_type`, `display_name` and `extra_body_parameters`; keywords left
|
|
1098
|
-
`nil` are not sent.
|
|
1054
|
+
`nil` are not sent. An empty file name or a `content_length` that is not
|
|
1055
|
+
positive raises `ArgumentError` before any request. The upload URL is a pre-signed storage URL outside of the
|
|
1099
1056
|
DeepL API, so no authorization header and, of the configured `headers`, only a
|
|
1100
1057
|
`User-Agent` is sent with the upload; the proxy, SSL and timeout settings of the client apply. A non-2xx
|
|
1101
1058
|
reply of a storage URL (for example 403 for an expired URL) raises a plain
|
|
@@ -1128,10 +1085,13 @@ finish on its own, and a status the library does not know keeps it polling too,
|
|
|
1128
1085
|
|
|
1129
1086
|
`export_translation_memory_to_filepath` writes a translation memory to a TMX
|
|
1130
1087
|
file. It creates the export job, waits until it is completed and downloads the
|
|
1131
|
-
result
|
|
1132
|
-
`
|
|
1133
|
-
|
|
1134
|
-
|
|
1088
|
+
result. It accepts `timeout_s` and wraps every failure in a
|
|
1089
|
+
`DeepL::Exceptions::TranslationMemoryJobError` with the original error as
|
|
1090
|
+
`cause`: an output file that already exists or a directory that does not exist or
|
|
1091
|
+
is not writable (checked before the job is created, `job_id` and `job` are `nil`),
|
|
1092
|
+
a job that fails or expires, an expired `timeout_s`, and a failed download or
|
|
1093
|
+
write. Its `job_id` is set once the job was created, and `job` is the last job
|
|
1094
|
+
status fetched.
|
|
1135
1095
|
|
|
1136
1096
|
```rb
|
|
1137
1097
|
job = client.export_translation_memory_to_filepath('YOUR_TM_ID', 'export.tmx')
|
|
@@ -1146,6 +1106,10 @@ The steps can be performed separately as well, with
|
|
|
1146
1106
|
translation memory reuses the previously completed job instead of starting a new
|
|
1147
1107
|
one, which `reused_existing?` reports. Just like the upload URL, the download URL
|
|
1148
1108
|
is a pre-signed storage URL and is requested without an authorization header.
|
|
1109
|
+
`download_translation_memory_export` raises a `SystemCallError` before the
|
|
1110
|
+
download if the output file exists (`Errno::EEXIST`) or its directory is missing
|
|
1111
|
+
or not writable (`Errno::ENOENT`, `Errno::EACCES`), and the `Errno` error of
|
|
1112
|
+
writing the file.
|
|
1149
1113
|
|
|
1150
1114
|
```rb
|
|
1151
1115
|
created = client.create_translation_memory_export('YOUR_TM_ID')
|
|
@@ -1172,8 +1136,8 @@ waiting forever; the last wait is cut so that the call never waits longer than
|
|
|
1172
1136
|
`timeout_s`.
|
|
1173
1137
|
|
|
1174
1138
|
`done?` is `true` once the job is completed, `ok?` is `false` once it failed or
|
|
1175
|
-
expired (and `true` while it runs), and `finished?` is `true`
|
|
1176
|
-
|
|
1139
|
+
expired (and `true` while it runs), and `finished?` is `true` once it is
|
|
1140
|
+
completed, failed or expired.
|
|
1177
1141
|
|
|
1178
1142
|
```rb
|
|
1179
1143
|
job = client.get_translation_memory_job('YOUR_JOB_ID')
|
|
@@ -1186,8 +1150,8 @@ puts [job.done?, job.ok?, job.finished?].inspect
|
|
|
1186
1150
|
# => [false, true, false]
|
|
1187
1151
|
```
|
|
1188
1152
|
|
|
1189
|
-
The status is one of `awaiting_input`, `processing`, `completed`, `
|
|
1190
|
-
`
|
|
1153
|
+
The status is one of `awaiting_input`, `processing`, `completed`, `failed` or
|
|
1154
|
+
`expired`.
|
|
1191
1155
|
|
|
1192
1156
|
#### Deleting a translation memory
|
|
1193
1157
|
|
|
@@ -1197,23 +1161,14 @@ The status is one of `awaiting_input`, `processing`, `completed`, `downloaded`,
|
|
|
1197
1161
|
client.delete_translation_memory('YOUR_TM_ID')
|
|
1198
1162
|
```
|
|
1199
1163
|
|
|
1200
|
-
The deprecated module-level `DeepL.translation_memories` (`list`, `find`,
|
|
1201
|
-
`segments`, `destroy`, `create_import`, `upload_file`, `import_from_filepath`,
|
|
1202
|
-
`create_export`, `download_export`, `export_to_filepath`, `find_job`,
|
|
1203
|
-
`wait_until_job_done`) keeps working unchanged. Its `import_from_filepath` also
|
|
1204
|
-
accepts `content_type` and `extra_body_parameters`, and `create_import` accepts
|
|
1205
|
-
`extra_body_parameters`. Its file helpers raise `DeepL::Exceptions::Error` for a
|
|
1206
|
-
missing input file and the raw `Errno::*` error for other local file failures,
|
|
1207
|
-
such as an unreadable input file or a missing output directory (checked before
|
|
1208
|
-
the export job is created).
|
|
1209
|
-
|
|
1210
1164
|
#### Using a translation memory in translations
|
|
1211
1165
|
|
|
1212
1166
|
Pass the `translation_memory` option to `translate_text` to use a translation
|
|
1213
1167
|
memory. You can pass either a string containing the translation memory ID, or a
|
|
1214
1168
|
`TranslationMemory` object. Use `translation_memory_threshold` to control the
|
|
1215
1169
|
minimum matching percentage for fuzzy matches (0-100, recommended minimum of
|
|
1216
|
-
75%).
|
|
1170
|
+
75%). It requires `translation_memory`; without it, or with a value outside 0 to
|
|
1171
|
+
100, it raises `ArgumentError` before anything is sent.
|
|
1217
1172
|
|
|
1218
1173
|
```rb
|
|
1219
1174
|
# Using a translation memory ID
|
|
@@ -1241,9 +1196,10 @@ handle = client.translate_document_upload('my_document.docx', 'EN', 'DE',
|
|
|
1241
1196
|
### Monitor usage
|
|
1242
1197
|
|
|
1243
1198
|
To check current API usage, call `get_usage`. It returns a `DeepL::Resources::Usage`. Each
|
|
1244
|
-
usage type is a `DeepL::Resources::Usage::Detail` with `count`, `limit` and `limit_reached
|
|
1245
|
-
`
|
|
1246
|
-
|
|
1199
|
+
usage type is a `DeepL::Resources::Usage::Detail` with `count`, `limit` and `limit_reached?`.
|
|
1200
|
+
`any_character_limit_reached?` is `true` if the account's character limit (`character`) or this
|
|
1201
|
+
API key's character limit (`api_key_character`, API Pro) is reached; the speech minutes have
|
|
1202
|
+
their own details:
|
|
1247
1203
|
|
|
1248
1204
|
```rb
|
|
1249
1205
|
usage = client.get_usage
|
|
@@ -1252,19 +1208,14 @@ puts usage.character.count
|
|
|
1252
1208
|
# => 180118
|
|
1253
1209
|
puts usage.character.limit
|
|
1254
1210
|
# => 1250000
|
|
1255
|
-
puts '
|
|
1256
|
-
puts "Document usage: #{usage.document}" if usage.document
|
|
1257
|
-
# => Document usage: 5 of 10
|
|
1211
|
+
puts 'Character limit reached.' if usage.any_character_limit_reached?
|
|
1258
1212
|
```
|
|
1259
1213
|
|
|
1260
|
-
`DeepL.usage` and the `Usage` readers `character_count`, `character_limit` and
|
|
1261
|
-
`quota_exceeded?` are deprecated. Use `client.get_usage`, `character.count`,
|
|
1262
|
-
`character.limit` and `character.limit_reached?` (or `any_limit_reached?`) instead.
|
|
1263
|
-
|
|
1264
1214
|
For API Pro users, the response also contains this API key's usage, speech usage, the billing
|
|
1265
1215
|
period and a per-product breakdown. These fields are `nil` when the response does not contain
|
|
1266
|
-
them (e.g. for API Free users). `
|
|
1267
|
-
`limit_reached?` on
|
|
1216
|
+
them (e.g. for API Free users). `any_character_limit_reached?` considers `api_key_character`
|
|
1217
|
+
but not the speech usage; call `limit_reached?` on it directly, e.g.
|
|
1218
|
+
`usage.speech_to_text_minutes.limit_reached?`:
|
|
1268
1219
|
|
|
1269
1220
|
```rb
|
|
1270
1221
|
usage = client.get_usage
|
|
@@ -1302,9 +1253,11 @@ puts status.billed_characters
|
|
|
1302
1253
|
# => 2045
|
|
1303
1254
|
```
|
|
1304
1255
|
|
|
1305
|
-
A missing input file raises `ArgumentError` before anything is sent. Every other failure
|
|
1306
|
-
an existing output file
|
|
1307
|
-
|
|
1256
|
+
A missing input file raises `ArgumentError` before anything is sent. Every other failure raises
|
|
1257
|
+
`DeepL::Exceptions::DocumentTranslationError`: an existing output file (which is kept) or one
|
|
1258
|
+
whose directory is missing or not writable, and an invalid argument of the upload such as an
|
|
1259
|
+
unknown option, all detected before anything is sent (`document_handle` is `nil`), as well as a
|
|
1260
|
+
failed upload or translation. Once the upload succeeded, its `document_handle`
|
|
1308
1261
|
is set, so you can still query the status and download the document. If a DeepL error caused
|
|
1309
1262
|
it, its `http_status_code` and `should_retry?` are copied from that error. `timeout_s:` limits the wait after the upload in seconds; by default
|
|
1310
1263
|
`translate_document` waits until the translation is done or failed:
|
|
@@ -1326,7 +1279,9 @@ until the translation is done and returns that status; it raises `DeepL::Excepti
|
|
|
1326
1279
|
with the API's error message if the translation fails, and when `timeout_s` expires. A status
|
|
1327
1280
|
the library does not know keeps it polling, so pass `timeout_s` to bound the wait.
|
|
1328
1281
|
`translate_document_get_status` queries the status once, and `translate_document_download`
|
|
1329
|
-
writes the translated document
|
|
1282
|
+
writes the translated document to a path that must not exist yet. Before the request it raises
|
|
1283
|
+
a `SystemCallError` if the output file exists (`Errno::EEXIST`) or its directory is missing or
|
|
1284
|
+
not writable (`Errno::ENOENT`, `Errno::EACCES`); it raises
|
|
1330
1285
|
`DeepL::Exceptions::DocumentNotReadyError` if the translation is not done yet.
|
|
1331
1286
|
|
|
1332
1287
|
```rb
|
|
@@ -1343,22 +1298,7 @@ A `DeepL::Resources::DocumentTranslationStatus` has `document_id`, `status` (a s
|
|
|
1343
1298
|
`DeepL::Constants::DocumentStatusCode` has the values `QUEUED`, `TRANSLATING`, `DONE` and
|
|
1344
1299
|
`ERROR`), `seconds_remaining`, `billed_characters` and `error_message`, and the predicates
|
|
1345
1300
|
`done?` (done), `error?` (failed), `ok?` (not failed, also while queued or translating)
|
|
1346
|
-
and `finished?` (done or failed).
|
|
1347
|
-
|
|
1348
|
-
With the deprecated module-level API, the same methods are `DeepL.document.translate_document`,
|
|
1349
|
-
`upload`, `get_status` and `download`, which take the filename as a positional parameter and
|
|
1350
|
-
optional additional headers. `DeepL.document.translate_document` waits until the translation is
|
|
1351
|
-
done or failed and returns the number of bytes written; the deprecated configuration setting
|
|
1352
|
-
`max_doc_status_queries` limits the number of status requests. The deprecated
|
|
1353
|
-
`DocumentHandle#wait_until_document_translation_finished` returns the final status also when
|
|
1354
|
-
the translation failed. `DeepL.document.translate_document` raises
|
|
1355
|
-
`DeepL::Exceptions::DocumentTranslationError` if the output file already exists.
|
|
1356
|
-
|
|
1357
|
-
```rb
|
|
1358
|
-
doc_handle = DeepL.document.upload('/path/to/spanish_document.pdf', 'ES', 'EN')
|
|
1359
|
-
doc_status = doc_handle.wait_until_document_translation_finished
|
|
1360
|
-
DeepL.document.download(doc_handle, '/path/to/translated_document.pdf') unless doc_status.error?
|
|
1361
|
-
```
|
|
1301
|
+
and `finished?` (done or failed).
|
|
1362
1302
|
|
|
1363
1303
|
You can also pass additional options to document translation methods, including `extra_body_parameters`:
|
|
1364
1304
|
|
|
@@ -1370,11 +1310,10 @@ doc_handle = client.translate_document_upload('/path/to/spanish_document.pdf', '
|
|
|
1370
1310
|
|
|
1371
1311
|
Document translation options include:
|
|
1372
1312
|
|
|
1373
|
-
- `filename
|
|
1313
|
+
- `filename`: the file name sent with the upload, including its
|
|
1374
1314
|
extension. Defaults to the base name of the input path.
|
|
1375
1315
|
- `formality`: same as for text translation.
|
|
1376
|
-
- `glossary` / `glossary_ids`: see the glossary sections above.
|
|
1377
|
-
use `glossary`.
|
|
1316
|
+
- `glossary` / `glossary_ids`: see the glossary sections above.
|
|
1378
1317
|
- `output_format`: file extension of the desired output format, e.g. `'pdf'` to translate
|
|
1379
1318
|
a `docx` into a PDF.
|
|
1380
1319
|
- `enable_watermark`: `true` adds a "Translated by DeepL" watermark to the translated
|
|
@@ -1389,13 +1328,13 @@ client.translate_document('/path/to/document.docx', '/path/to/translated.pdf', '
|
|
|
1389
1328
|
output_format: 'pdf', enable_watermark: true)
|
|
1390
1329
|
```
|
|
1391
1330
|
|
|
1392
|
-
The `extra_body_parameters` option allows you to pass arbitrary parameters in the request body. This can be used to access beta features by adding new parameters, or to override built-in parameters (such as `target_lang`, `source_lang`, etc.) for testing purposes.
|
|
1331
|
+
The `extra_body_parameters` option allows you to pass arbitrary parameters in the request body. This can be used to access beta features by adding new parameters, or to override built-in parameters (such as `target_lang`, `source_lang`, etc.) for testing purposes. In a document upload, a `nil` value removes the field from the form, the library's own field of that name included.
|
|
1393
1332
|
|
|
1394
1333
|
### Admin API
|
|
1395
1334
|
|
|
1396
1335
|
The Admin API lets you manage the developer keys of your organization and retrieve usage analytics. It requires an admin API key, which you can create in the "Admin API Keys" tab of your DeepL account. Admin keys cannot be used for translation, and developer keys cannot access the Admin API: the API rejects a wrong key with `DeepL::Exceptions::AuthorizationFailed`.
|
|
1397
1336
|
|
|
1398
|
-
Create a `DeepL::AdminClient` with your admin key. It
|
|
1337
|
+
Create a `DeepL::AdminClient` with your admin key. It reads no environment variables and uses the `https://api.deepl.com` server by default. The admin key is trimmed. It also accepts the `server_url:`, `headers:`, `max_retries:`, `timeout:`, `proxy:`, `send_platform_info:`, `app_info:`, `http_client_options:` and `logger:` keyword arguments of [`DeepL::Client`](#creating-a-client); without `server_url:` it uses `https://api.deepl.com`, also for keys ending in `:fx`.
|
|
1399
1338
|
|
|
1400
1339
|
```rb
|
|
1401
1340
|
admin_client = DeepL::AdminClient.new('YOUR_ADMIN_KEY')
|
|
@@ -1423,9 +1362,9 @@ key = admin_client.set_developer_key_usage_limits(key, speech_to_speech_millisec
|
|
|
1423
1362
|
admin_client.deactivate_developer_key(key)
|
|
1424
1363
|
```
|
|
1425
1364
|
|
|
1426
|
-
`rename_developer_key`, `set_developer_key_usage_limits` and `deactivate_developer_key` accept either a key ID or a `DeepL::Resources::DeveloperKey` object and return the updated `DeepL::Resources::DeveloperKey`. `set_developer_key_usage_limits` accepts `characters:`, `speech_to_text_milliseconds:` and `speech_to_speech_milliseconds
|
|
1365
|
+
`rename_developer_key`, `set_developer_key_usage_limits` and `deactivate_developer_key` accept either a key ID or a `DeepL::Resources::DeveloperKey` object and return the updated `DeepL::Resources::DeveloperKey`. `set_developer_key_usage_limits` accepts `characters:`, `speech_to_text_milliseconds:` and `speech_to_speech_milliseconds:`; any other keyword raises `ArgumentError` before a request is sent (send fields the library does not model with `extra_body_parameters:`). `create_developer_key` takes the label as the `label:` keyword argument; without it the API labels the key "DeepL API Key". Label and limit values are sent as given and validated by the API. `create_developer_key`, `deactivate_developer_key`, `rename_developer_key` and `set_developer_key_usage_limits` also accept `extra_body_parameters:`, a hash added to the request body last that replaces fields of the same name. A response without a `key_id` raises `DeepL::Exceptions::Error`. `label` and `usage_limits` are `nil` when the response does not contain them.
|
|
1427
1366
|
|
|
1428
|
-
A failed `create_developer_key` request is retried only after HTTP 429, a DNS resolution error or a connection timeout, when the API cannot have created the key. Other requests are retried like all other requests of the library.
|
|
1367
|
+
A failed `create_developer_key` request is retried only after HTTP 429 or a transient network failure while connecting, such as a DNS resolution error, a refused connection, an unreachable host or network, a connection timeout or a reset during the TLS or proxy handshake, when the API cannot have created the key, like the other requests of the library that create a resource. Other requests are retried like all other requests of the library.
|
|
1429
1368
|
|
|
1430
1369
|
#### Retrieving usage analytics
|
|
1431
1370
|
|
|
@@ -1458,17 +1397,15 @@ end
|
|
|
1458
1397
|
### Sending additional HTTP headers
|
|
1459
1398
|
|
|
1460
1399
|
`DeepL::Client.new(key, headers: { 'X-DeepL-Reporting-Tag' => 'my-tag' })` sends the headers
|
|
1461
|
-
with every DeepL API request of that client
|
|
1462
|
-
`document` methods. For example, to send the `X-DeepL-Reporting-Tag` header
|
|
1400
|
+
with every DeepL API request of that client, for example the `X-DeepL-Reporting-Tag` header
|
|
1463
1401
|
for usage reporting (see the [cookbook entry](https://developers.deepl.com/docs/learning-how-tos/cookbook/sending-custom-reporting-tags-from-client-libraries)):
|
|
1464
1402
|
|
|
1465
1403
|
```rb
|
|
1466
|
-
|
|
1467
|
-
translation =
|
|
1468
|
-
rephrased = DeepL.rephrase 'Hello, world!', 'EN', nil, nil, {}, additional_headers
|
|
1404
|
+
client = DeepL::Client.new(auth_key, headers: { 'X-DeepL-Reporting-Tag' => 'my-tag' })
|
|
1405
|
+
translation = client.translate_text 'Hello, world!', 'EN', 'DE'
|
|
1469
1406
|
```
|
|
1470
1407
|
|
|
1471
|
-
A header in `headers:`
|
|
1408
|
+
A header in `headers:` replaces a library
|
|
1472
1409
|
header of the same name, in any casing, `Authorization` and `User-Agent` included, except
|
|
1473
1410
|
`Content-Type`, `Content-Length`, `Transfer-Encoding` and `Host`, which the library always sets.
|
|
1474
1411
|
Pre-signed translation memory storage URLs get only the `User-Agent`, the caller's if one is
|
|
@@ -1482,26 +1419,31 @@ You can capture and process exceptions that may be raised during API calls. Thes
|
|
|
1482
1419
|
| --------------- | ----------- |
|
|
1483
1420
|
| `DeepL::Exceptions::AuthorizationFailed` | The authorization process has failed. Check your `auth_key` value. |
|
|
1484
1421
|
| `DeepL::Exceptions::BadRequest` | Something is wrong in your request. Check `exception.message` for more information. |
|
|
1485
|
-
| `DeepL::Exceptions::ConnectionError` |
|
|
1422
|
+
| `DeepL::Exceptions::ConnectionError` | No complete HTTP response from the API: a DNS, connection or timeout failure, or a response body cut off before its `Content-Length`, after all retries (`should_retry?` is true), or a TLS failure, a proxy failure (the proxy refuses `CONNECT`) or a malformed response, raised without retrying (`should_retry?` is false). Requests that create a resource retry fewer failures, see [Retries and timeouts](#retries-and-timeouts). The original exception is `exception.cause`. |
|
|
1486
1423
|
| `DeepL::Exceptions::DocumentNotReadyError` | A subclass of `ServerError`: HTTP 503 on a document download, the translated document is not ready yet. |
|
|
1487
1424
|
| `DeepL::Exceptions::DocumentTranslationError` | An error occured during document translation. Check `exception.message` for more information; `exception.document_handle` is the handle of the uploaded document, `nil` if the upload failed; `http_status_code` and `should_retry?` are those of the DeepL error that caused it, if any. |
|
|
1425
|
+
| `DeepL::Exceptions::TranslationMemoryJobError` | Any failure of `import_translation_memory_from_filepath` or `export_translation_memory_to_filepath` except a missing input file. `exception.job_id` is the ID of the job once it was created, `nil` before; `exception.job` is the last `TranslationMemoryJob` status fetched, `nil` before the first status check; `exception.cause` is the original error, and `http_status_code` and `should_retry?` are those of a DeepL error cause. |
|
|
1488
1426
|
| `DeepL::Exceptions::LimitExceeded` | You've reached the API's call limit. |
|
|
1489
1427
|
| `DeepL::Exceptions::QuotaExceeded` | You've reached the API's character limit. |
|
|
1490
1428
|
| `DeepL::Exceptions::RequestError` | Any other HTTP error status. Its message contains the status and the API's message; check `exception.response` and `exception.request` for more information. |
|
|
1491
|
-
| `DeepL::Exceptions::NotSupported` | Deprecated. Raised only by the module-level API: `supports_formality?` of a source language from `DeepL.languages`. |
|
|
1492
1429
|
| `DeepL::Exceptions::RequestEntityTooLarge` | Your request is too large, reduce the amount of data you are sending. The API has a request size limit of 128 KiB. |
|
|
1493
1430
|
| `DeepL::Exceptions::ServerError` | An error occured in the DeepL API (HTTP 5xx), raised after all retries. |
|
|
1494
|
-
| `DeepL::Exceptions::ValidationError` | An invalid argument detected before any request: an invalid glossary or spoken terms term, or an unsupported `DeepL.languages` type. |
|
|
1495
1431
|
|
|
1496
1432
|
All of them are subclasses of `DeepL::Exceptions::Error`, which is also raised for a response
|
|
1497
|
-
that cannot be parsed.
|
|
1498
|
-
|
|
1433
|
+
that cannot be parsed. An invalid argument raises `ArgumentError` before any request is sent;
|
|
1434
|
+
for an invalid glossary or spoken terms term it is the subclass
|
|
1435
|
+
`DeepL::Exceptions::ValidationError`. A method that writes a file raises a `SystemCallError`
|
|
1436
|
+
(`Errno::*`) for an output path it cannot use, where its documentation says so. Errors of an
|
|
1437
|
+
HTTP response carry the status as an `Integer` in
|
|
1438
|
+
`exception.http_status_code` (`nil` otherwise), and their message ends with the API's error
|
|
1439
|
+
message when the response has one, for example `Quota exceeded. The character limit has been
|
|
1440
|
+
reached: <API message>`.
|
|
1499
1441
|
|
|
1500
1442
|
An exampling of handling a generic exception:
|
|
1501
1443
|
|
|
1502
1444
|
```rb
|
|
1503
|
-
def my_method
|
|
1504
|
-
item =
|
|
1445
|
+
def my_method(client)
|
|
1446
|
+
item = client.translate_text 'This is my text', nil, 'ES'
|
|
1505
1447
|
rescue DeepL::Exceptions::RequestError => e
|
|
1506
1448
|
puts 'Oops!'
|
|
1507
1449
|
puts "Code: #{e.response.code}"
|
|
@@ -1512,7 +1454,7 @@ end
|
|
|
1512
1454
|
|
|
1513
1455
|
### Logging
|
|
1514
1456
|
|
|
1515
|
-
To enable logging, pass a suitable logging object (e.g. the default `Logger` from the Ruby standard library)
|
|
1457
|
+
To enable logging, pass a suitable logging object (e.g. the default `Logger` from the Ruby standard library) as the `logger:` of the client. The library logs HTTP requests to `INFO` and debug information to `DEBUG`. Example:
|
|
1516
1458
|
|
|
1517
1459
|
```rb
|
|
1518
1460
|
require 'logger'
|
|
@@ -1520,10 +1462,7 @@ require 'logger'
|
|
|
1520
1462
|
logger = Logger.new(STDOUT)
|
|
1521
1463
|
logger.level = Logger::INFO
|
|
1522
1464
|
|
|
1523
|
-
DeepL.
|
|
1524
|
-
config.auth_key = ENV.fetch('DEEPL_AUTH_KEY')
|
|
1525
|
-
config.logger = logger
|
|
1526
|
-
end
|
|
1465
|
+
client = DeepL::Client.new(ENV.fetch('DEEPL_AUTH_KEY'), logger: logger)
|
|
1527
1466
|
```
|
|
1528
1467
|
|
|
1529
1468
|
### Retries and timeouts
|
|
@@ -1532,64 +1471,54 @@ Requests that fail with HTTP 429, any 5xx status or a transient network failure
|
|
|
1532
1471
|
or reset connection, broken pipe, unreachable host, timeout, response body cut off before its
|
|
1533
1472
|
`Content-Length`) are retried up to `max_retries:`
|
|
1534
1473
|
times (default 5) with exponential backoff; a request is sent at most `max_retries:` + 1 times.
|
|
1535
|
-
Each attempt has a timeout of `timeout:` seconds (default 10
|
|
1536
|
-
|
|
1537
|
-
`DeepL::Exceptions::ConnectionError` in `DeepL::Client` and `DeepL::AdminClient`; the
|
|
1538
|
-
module-level API raises the original network error. TLS failures (including certificate
|
|
1474
|
+
Each attempt has a timeout of `timeout:` seconds (default 10). After the last retry, network
|
|
1475
|
+
failures raise `DeepL::Exceptions::ConnectionError`. TLS failures (including certificate
|
|
1539
1476
|
verification), proxy failures (the proxy refuses `CONNECT`, e.g. with 407) and malformed
|
|
1540
1477
|
responses are not retried and are raised the same way at once.
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1478
|
+
Requests that create a resource are only retried when the request was not sent (HTTP 429, or a
|
|
1479
|
+
transient network failure while connecting, before any request byte is written: DNS failure, refused
|
|
1480
|
+
connection, unreachable host or network, connection timeout, a reset during the TLS or proxy
|
|
1481
|
+
handshake), so that a retry cannot create a second resource: `create_glossary`,
|
|
1482
|
+
`create_glossary_from_csv`, `create_multilingual_glossary`, `create_multilingual_glossary_from_csv`,
|
|
1483
|
+
`create_spoken_terms`, `create_style_rule`, `create_style_rule_custom_instruction`,
|
|
1484
|
+
`create_style_profile`, the document upload of `translate_document` and `translate_document_upload`,
|
|
1485
|
+
the translation memory import and export job creation, and `AdminClient#create_developer_key`. Their
|
|
1486
|
+
other failures are raised at once: a 5xx reply as `DeepL::Exceptions::ServerError` and a network
|
|
1487
|
+
failure as `DeepL::Exceptions::ConnectionError`, both with `should_retry?` false for a failure before
|
|
1488
|
+
the response. A response cut off mid-body, after its headers arrived, is not retried either, but its
|
|
1489
|
+
`DeepL::Exceptions::ConnectionError` has `should_retry?` true, whatever the network failure.
|
|
1544
1490
|
|
|
1545
1491
|
### Proxy configuration
|
|
1546
1492
|
|
|
1547
|
-
Pass a proxy
|
|
1493
|
+
Pass a proxy to the client as a URL string, a `URI`, or a hash with `proxy_addr` and
|
|
1494
|
+
`proxy_port` (string or symbol keys, both required):
|
|
1548
1495
|
|
|
1549
1496
|
```rb
|
|
1550
1497
|
client = DeepL::Client.new(auth_key, proxy: 'http://user:password@localhost:3128')
|
|
1498
|
+
client = DeepL::Client.new(auth_key, proxy: URI('http://localhost:3128'))
|
|
1499
|
+
client = DeepL::Client.new(auth_key, proxy: { proxy_addr: 'localhost', proxy_port: 3128 })
|
|
1551
1500
|
```
|
|
1552
1501
|
|
|
1553
|
-
|
|
1554
|
-
`
|
|
1555
|
-
|
|
1502
|
+
The URL scheme must be `http` or `https`; any other scheme raises `ArgumentError`. With an
|
|
1503
|
+
`https` proxy URL the connection to the proxy uses TLS. This needs net-http 0.5.0 or later
|
|
1504
|
+
(bundled from Ruby 3.4; on older Rubies add `gem 'net-http', '>= 0.5'`) and an `https` server
|
|
1505
|
+
URL; otherwise `ArgumentError` is raised. Net::HTTP does not verify the proxy's certificate. The
|
|
1506
|
+
hash form is always a plain HTTP proxy.
|
|
1556
1507
|
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
# ...
|
|
1561
|
-
end
|
|
1562
|
-
```
|
|
1563
|
-
|
|
1564
|
-
### Anonymous platform information
|
|
1565
|
-
|
|
1566
|
-
By default, we send some basic information about the platform the client library is running on with each request, see [here for an explanation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent). This data is completely anonymous and only used to improve our product, not track any individual users. If you do not wish to send this data, create the client with `send_platform_info: false`, or with the module-level API set the `User-Agent` to the library name and version only:
|
|
1508
|
+
Any other value, such as a hash with only one of the two keys or a blank `proxy_addr`, a URL with an
|
|
1509
|
+
empty host (`http://`, `http://:8080`) or a URL with another scheme, raises `ArgumentError`. `DeepL::HTTPClientOptions` takes the proxy in the same forms, together with
|
|
1510
|
+
certificate, SSL verification and timeout options, given as `http_client_options:`:
|
|
1567
1511
|
|
|
1568
1512
|
```rb
|
|
1569
|
-
DeepL.
|
|
1570
|
-
|
|
1571
|
-
end
|
|
1572
|
-
```
|
|
1573
|
-
|
|
1574
|
-
You can also completely replace the `User-Agent` header with `headers: { 'User-Agent' => 'myCustomUserAgent' }`, or with the module-level API like so:
|
|
1575
|
-
|
|
1576
|
-
```rb
|
|
1577
|
-
DeepL.configure do |config|
|
|
1578
|
-
config.user_agent = 'myCustomUserAgent'
|
|
1579
|
-
end
|
|
1513
|
+
options = DeepL::HTTPClientOptions.new({ 'proxy_addr' => 'localhost', 'proxy_port' => 3128 })
|
|
1514
|
+
client = DeepL::Client.new(auth_key, http_client_options: options)
|
|
1580
1515
|
```
|
|
1581
1516
|
|
|
1582
|
-
###
|
|
1517
|
+
### Anonymous platform information
|
|
1583
1518
|
|
|
1584
|
-
|
|
1519
|
+
By default, we send some basic information about the platform the client library is running on with each request, see [here for an explanation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent). This data is completely anonymous and only used to improve our product, not track any individual users. If you do not wish to send this data, create the client with `send_platform_info: false`.
|
|
1585
1520
|
|
|
1586
|
-
|
|
1587
|
-
DeepL.with_session do |session|
|
|
1588
|
-
DeepL.translate(sentence1, 'DE', 'EN-GB')
|
|
1589
|
-
DeepL.translate(sentence2, 'DE', 'EN-GB')
|
|
1590
|
-
DeepL.translate(sentence3, 'DE', 'EN-GB')
|
|
1591
|
-
end
|
|
1592
|
-
```
|
|
1521
|
+
You can also completely replace the `User-Agent` header with `headers: { 'User-Agent' => 'myCustomUserAgent' }`.
|
|
1593
1522
|
|
|
1594
1523
|
### Writing a plugin
|
|
1595
1524
|
|
|
@@ -1600,15 +1529,7 @@ client = DeepL::Client.new(auth_key, app_info: { app_name: 'MyTranslationPlugin'
|
|
|
1600
1529
|
app_version: '1.0.1' })
|
|
1601
1530
|
```
|
|
1602
1531
|
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
```rb
|
|
1606
|
-
DeepL.configure do |config|
|
|
1607
|
-
config.user_agent = "#{config.user_agent} MyTranslationPlugin/1.0.1"
|
|
1608
|
-
end
|
|
1609
|
-
```
|
|
1610
|
-
|
|
1611
|
-
This information is passed along when the library makes calls to the DeepL API. Both name and version are required. Please note that setting the `User-Agent` header via `DeepL.configure` will override this setting, if you need to use this, please manually identify your Application in the `User-Agent` header.
|
|
1532
|
+
This information is passed along when the library makes calls to the DeepL API. Both name and version are required. Please note that a `User-Agent` in `headers:` overrides this setting; if you set one, identify your application in it yourself.
|
|
1612
1533
|
|
|
1613
1534
|
## Options Constants
|
|
1614
1535
|
|
|
@@ -1638,19 +1559,14 @@ DeepL::Constants::Tone.valid?('rude') # false
|
|
|
1638
1559
|
|
|
1639
1560
|
### Ruby on Rails
|
|
1640
1561
|
|
|
1641
|
-
You may
|
|
1642
|
-
|
|
1562
|
+
You may create one client in an initializer on your `config/initializers` folder and use it
|
|
1563
|
+
anywhere in your code (controllers, models, views, jobs, plain ruby objects…). For example:
|
|
1643
1564
|
|
|
1644
1565
|
```rb
|
|
1645
1566
|
# config/initializers/deepl.rb
|
|
1646
|
-
DeepL.
|
|
1647
|
-
# Your configuration goes here
|
|
1648
|
-
end
|
|
1567
|
+
DEEPL_CLIENT = DeepL::Client.new(Rails.application.credentials.deepl_auth_key)
|
|
1649
1568
|
```
|
|
1650
1569
|
|
|
1651
|
-
Since the DeepL service is defined globally, you can use service anywhere in your code
|
|
1652
|
-
(controllers, models, views, jobs, plain ruby objects… you name it).
|
|
1653
|
-
|
|
1654
1570
|
### i18n-tasks
|
|
1655
1571
|
|
|
1656
1572
|
You may also take a look at [`i18n-tasks`](https://github.com/glebm/i18n-tasks), which is a gem
|