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.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +313 -1
  4. data/README.md +225 -309
  5. data/Rakefile +17 -8
  6. data/VERSION +1 -1
  7. data/deepl-rb.gemspec +73 -86
  8. data/lib/deepl/admin_client.rb +39 -14
  9. data/lib/deepl/api.rb +3 -17
  10. data/lib/deepl/app_info.rb +0 -1
  11. data/lib/deepl/client.rb +399 -84
  12. data/lib/deepl/configuration.rb +19 -70
  13. data/lib/deepl/exceptions/authorization_failed.rb +1 -1
  14. data/lib/deepl/exceptions/connection_error.rb +10 -7
  15. data/lib/deepl/exceptions/limit_exceeded.rb +1 -1
  16. data/lib/deepl/exceptions/quota_exceeded.rb +1 -1
  17. data/lib/deepl/exceptions/request_entity_too_large.rb +1 -2
  18. data/lib/deepl/exceptions/request_error.rb +7 -0
  19. data/lib/deepl/exceptions/server_error.rb +2 -1
  20. data/lib/deepl/exceptions/translation_memory_job_error.rb +32 -0
  21. data/lib/deepl/exceptions/validation_error.rb +3 -2
  22. data/lib/deepl/requests/base.rb +129 -51
  23. data/lib/deepl/requests/correct.rb +2 -8
  24. data/lib/deepl/requests/document/upload.rb +29 -26
  25. data/lib/deepl/requests/glossary/base.rb +30 -0
  26. data/lib/deepl/requests/glossary/create.rb +18 -22
  27. data/lib/deepl/requests/glossary/destroy.rb +4 -16
  28. data/lib/deepl/requests/glossary/entries.rb +6 -14
  29. data/lib/deepl/requests/glossary/find.rb +3 -13
  30. data/lib/deepl/requests/glossary/language_pairs.rb +2 -2
  31. data/lib/deepl/requests/glossary/list.rb +2 -2
  32. data/lib/deepl/requests/languages.rb +6 -11
  33. data/lib/deepl/requests/languages_for_resource.rb +2 -0
  34. data/lib/deepl/requests/multilingual_glossary/create.rb +8 -0
  35. data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +4 -0
  36. data/lib/deepl/requests/multilingual_glossary/entries.rb +5 -3
  37. data/lib/deepl/requests/multilingual_glossary/helpers.rb +22 -14
  38. data/lib/deepl/requests/rephrase.rb +3 -1
  39. data/lib/deepl/requests/spoken_terms/create.rb +5 -0
  40. data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +1 -0
  41. data/lib/deepl/requests/spoken_terms/entries.rb +1 -0
  42. data/lib/deepl/requests/spoken_terms/helpers.rb +9 -2
  43. data/lib/deepl/requests/style_profile/create.rb +5 -0
  44. data/lib/deepl/requests/style_profile/list.rb +2 -2
  45. data/lib/deepl/requests/style_rule/create.rb +25 -1
  46. data/lib/deepl/requests/style_rule/create_custom_instruction.rb +7 -0
  47. data/lib/deepl/requests/style_rule/helpers.rb +13 -4
  48. data/lib/deepl/requests/style_rule/list.rb +2 -0
  49. data/lib/deepl/requests/style_rule/update.rb +1 -0
  50. data/lib/deepl/requests/style_rule/update_custom_instruction.rb +2 -0
  51. data/lib/deepl/requests/translate.rb +20 -36
  52. data/lib/deepl/requests/translation_memory/create_export.rb +6 -1
  53. data/lib/deepl/requests/translation_memory/create_import.rb +10 -0
  54. data/lib/deepl/requests/translation_memory/download_export.rb +0 -4
  55. data/lib/deepl/requests/translation_memory/list.rb +2 -2
  56. data/lib/deepl/requests/translation_memory/segments.rb +2 -2
  57. data/lib/deepl/requests/translation_memory/storage_base.rb +5 -9
  58. data/lib/deepl/requests/write_improvements.rb +7 -0
  59. data/lib/deepl/resources/document_handle.rb +1 -26
  60. data/lib/deepl/resources/document_translation_status.rb +0 -12
  61. data/lib/deepl/resources/language.rb +4 -10
  62. data/lib/deepl/resources/multilingual_glossary.rb +4 -4
  63. data/lib/deepl/resources/style_rule.rb +1 -23
  64. data/lib/deepl/resources/translation_memory_job.rb +3 -4
  65. data/lib/deepl/resources/usage.rb +5 -38
  66. data/lib/deepl/utils/client_builder.rb +44 -9
  67. data/lib/deepl/utils/glossary_entries.rb +30 -0
  68. data/lib/deepl/utils/http_client_builder.rb +50 -13
  69. data/lib/deepl/utils/output_path.rb +25 -0
  70. data/lib/deepl/utils/term_validator.rb +3 -3
  71. data/lib/deepl/utils/translation_memory_operations.rb +230 -0
  72. data/lib/deepl.rb +6 -171
  73. data/lib/http_client_options.rb +2 -2
  74. data/lib/version.rb +1 -1
  75. data/upgrading_to_v4.md +374 -0
  76. metadata +9 -50
  77. data/.gitlab-ci.yml +0 -197
  78. data/lib/deepl/deprecation.rb +0 -42
  79. data/lib/deepl/document_api.rb +0 -150
  80. data/lib/deepl/exceptions/not_supported.rb +0 -20
  81. data/lib/deepl/glossary_api.rb +0 -38
  82. data/lib/deepl/style_rule_api.rb +0 -72
  83. data/lib/deepl/translation_memory_api.rb +0 -389
  84. data/license_checker.sh +0 -8
  85. data/spec/fixtures.rb +0 -33
  86. data/spec/offline/admin_client_spec.rb +0 -551
  87. data/spec/offline/client_spec.rb +0 -273
  88. data/spec/offline/configuration_spec.rb +0 -164
  89. data/spec/offline/constants_spec.rb +0 -180
  90. data/spec/offline/correct_text_spec.rb +0 -50
  91. data/spec/offline/deprecation_spec.rb +0 -32
  92. data/spec/offline/errors_spec.rb +0 -92
  93. data/spec/offline/glossaries_spec.rb +0 -98
  94. data/spec/offline/http_client_spec.rb +0 -319
  95. data/spec/offline/languages_spec.rb +0 -155
  96. data/spec/offline/module_methods_spec.rb +0 -13
  97. data/spec/offline/multilingual_glossaries_spec.rb +0 -358
  98. data/spec/offline/offline_helper.rb +0 -71
  99. data/spec/offline/rephrase_text_spec.rb +0 -73
  100. data/spec/offline/spoken_terms_spec.rb +0 -215
  101. data/spec/offline/style_profiles_spec.rb +0 -266
  102. data/spec/offline/style_rules_spec.rb +0 -318
  103. data/spec/offline/translate_document_spec.rb +0 -606
  104. data/spec/offline/translate_text_spec.rb +0 -286
  105. data/spec/offline/translation_memories_client_spec.rb +0 -256
  106. data/spec/offline/translation_memories_spec.rb +0 -463
  107. data/spec/offline/usage_spec.rb +0 -151
  108. data/spec/real_api/admin_client_spec.rb +0 -77
  109. data/spec/real_api/correct_text_spec.rb +0 -20
  110. data/spec/real_api/glossaries_spec.rb +0 -28
  111. data/spec/real_api/languages_spec.rb +0 -27
  112. data/spec/real_api/multilingual_glossaries_spec.rb +0 -53
  113. data/spec/real_api/proxy_spec.rb +0 -41
  114. data/spec/real_api/real_api_helper.rb +0 -65
  115. data/spec/real_api/rephrase_text_spec.rb +0 -16
  116. data/spec/real_api/spoken_terms_spec.rb +0 -56
  117. data/spec/real_api/style_profiles_spec.rb +0 -46
  118. data/spec/real_api/style_rules_spec.rb +0 -46
  119. data/spec/real_api/translate_document_spec.rb +0 -18
  120. data/spec/real_api/translate_text_spec.rb +0 -16
  121. data/spec/real_api/translation_memories_spec.rb +0 -56
  122. data/spec/real_api/usage_spec.rb +0 -20
  123. data/spec/spec_helper.rb +0 -13
@@ -1,389 +0,0 @@
1
- # Copyright 2026 DeepL SE (https://www.deepl.com)
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE.md file.
4
- # frozen_string_literal: true
5
-
6
- module DeepL
7
- # @deprecated Use the translation memory methods of DeepL::Client instead.
8
- class TranslationMemoryApi # rubocop:disable Metrics/ClassLength
9
- # Time to wait between two status queries of an import or export job.
10
- JOB_POLLING_INTERVAL_SECONDS = 5
11
-
12
- def initialize(api, options = {})
13
- @api = api
14
- @options = options
15
- end
16
-
17
- ##
18
- # Lists the translation memories of the account.
19
- #
20
- # @param [Hash] options Additional options for the request. Supports `page` (page number for
21
- # pagination, 0-indexed) and `page_size` (number of items per page).
22
- # @return [Array<DeepL::Resources::TranslationMemory>] The translation memories of the page.
23
- #
24
- # @deprecated Use DeepL::Client#list_translation_memories instead.
25
-
26
- def list(options = {})
27
- DeepL::Requests::TranslationMemory::List.new(@api, options).request
28
- end
29
-
30
- ##
31
- # Retrieves a single translation memory.
32
- #
33
- # @param [String, DeepL::Resources::TranslationMemory] translation_memory Translation memory
34
- # ID or object.
35
- # @param [Hash] options Additional options for the request.
36
- # @return [DeepL::Resources::TranslationMemory] The requested translation memory.
37
- #
38
- # @deprecated Use DeepL::Client#get_translation_memory instead.
39
-
40
- def find(translation_memory, options = {})
41
- DeepL::Requests::TranslationMemory::Find.new(
42
- @api, extract_translation_memory_id(translation_memory), options
43
- ).request
44
- end
45
-
46
- ##
47
- # Retrieves one page of the segments of a translation memory. Pagination is cursor-based:
48
- # omit `page_cursor` on the first call, then pass the `next_page_cursor` of the previous
49
- # response until it is nil.
50
- #
51
- # @param [String, DeepL::Resources::TranslationMemory] translation_memory Translation memory
52
- # ID or object.
53
- # @param [Hash] options Additional options for the request. Supports `page_size` (maximum
54
- # number of segments per page, 1-100, defaults to 50), `page_cursor`
55
- # (cursor of a previous response), `filter_text` (substring filter
56
- # across source and target text, at least 2 characters) and
57
- # `filter_case_sensitive` (whether the filter is case-sensitive,
58
- # defaults to false).
59
- # @return [DeepL::Resources::TranslationMemorySegments] The requested page of segments.
60
- #
61
- # @deprecated Use DeepL::Client#list_translation_memory_segments instead.
62
-
63
- def segments(translation_memory, options = {})
64
- DeepL::Requests::TranslationMemory::Segments.new(
65
- @api, extract_translation_memory_id(translation_memory), options
66
- ).request
67
- end
68
-
69
- ##
70
- # Deletes a translation memory.
71
- #
72
- # @param [String, DeepL::Resources::TranslationMemory] translation_memory Translation memory
73
- # ID or object.
74
- # @param [Hash] options Additional options for the request.
75
- # @return [String] The ID of the deleted translation memory.
76
- #
77
- # @deprecated Use DeepL::Client#delete_translation_memory instead.
78
-
79
- def destroy(translation_memory, options = {})
80
- DeepL::Requests::TranslationMemory::Destroy.new(
81
- @api, extract_translation_memory_id(translation_memory), options
82
- ).request
83
- end
84
-
85
- ##
86
- # Creates an import job for a new translation memory. The job only declares the file, upload
87
- # the TMX file itself to the returned upload URL with `upload_file`, then poll `find_job` for
88
- # the outcome. Use `import_from_filepath` to do all three steps at once.
89
- #
90
- # @param [String] file_name Name of the TMX file to import, for example "legal.tmx".
91
- # @param [Integer] content_length Size of the TMX file in bytes.
92
- # @param [String, nil] content_type MIME type of the file, defaults to "application/xml".
93
- # @param [String, nil] display_name Name of the resulting translation memory, defaults to the
94
- # file name.
95
- # @param [Hash, nil] extra_body_parameters Fields added to the request body last; they
96
- # replace fields of the same name.
97
- # @param [Hash] additional_headers Additional HTTP headers for the request.
98
- # @return [DeepL::Resources::TranslationMemoryImport] The job ID and the upload URL.
99
- #
100
- # @deprecated Use DeepL::Client#create_translation_memory_import instead.
101
-
102
- def create_import(file_name, content_length, content_type: nil, display_name: nil,
103
- extra_body_parameters: nil, additional_headers: {})
104
- options = { content_type: content_type, display_name: display_name,
105
- extra_body_parameters: extra_body_parameters }.compact
106
- DeepL::Requests::TranslationMemory::CreateImport.new(
107
- @api, file_name, content_length, options, additional_headers
108
- ).request
109
- end
110
-
111
- ##
112
- # Uploads a TMX file to the upload URL of an import job, which starts the processing. The
113
- # upload URL is a pre-signed storage URL outside of the DeepL API, so no authorization header
114
- # is sent with this request.
115
- #
116
- # @raise [DeepL::Exceptions::RequestError] If the storage URL replies with a non-2xx status:
117
- # the API error class for that status, e.g.
118
- # `AuthorizationFailed` for 401 and 403.
119
- #
120
- # @param [String, DeepL::Resources::TranslationMemoryImport] translation_memory_import Import
121
- # returned by `create_import`, or its upload URL.
122
- # @param [String] file_content Content of the TMX file.
123
- # @param [String] content_type MIME type of the file. Must match the `content_type` declared
124
- # when the import job was created.
125
- # @return [nil]
126
- #
127
- # @deprecated Use DeepL::Client#upload_translation_memory_file instead.
128
-
129
- def upload_file(translation_memory_import, file_content,
130
- content_type: Requests::TranslationMemory::UploadFile::DEFAULT_CONTENT_TYPE)
131
- DeepL::Requests::TranslationMemory::UploadFile.new(
132
- @api, extract_upload_url(translation_memory_import), file_content, content_type
133
- ).request
134
- end
135
-
136
- ##
137
- # Creates an export job for a translation memory. Poll `find_job` for the download URL of the
138
- # exported TMX file. Use `export_to_filepath` to do both steps and write the file at once.
139
- #
140
- # @param [String, DeepL::Resources::TranslationMemory] translation_memory Translation memory
141
- # ID or object.
142
- # @param [Hash] options Additional options for the request.
143
- # @return [DeepL::Resources::TranslationMemoryExport] The job ID, and whether the API reused a
144
- # previously completed export.
145
- #
146
- # @deprecated Use DeepL::Client#create_translation_memory_export instead.
147
-
148
- def create_export(translation_memory, options = {})
149
- DeepL::Requests::TranslationMemory::CreateExport.new(
150
- @api, extract_translation_memory_id(translation_memory), options
151
- ).request
152
- end
153
-
154
- ##
155
- # Retrieves the status of a translation memory import or export job.
156
- #
157
- # @param [String, DeepL::Resources::TranslationMemoryJob] job Job ID or object.
158
- # @param [Hash] options Additional options for the request.
159
- # @return [DeepL::Resources::TranslationMemoryJob] The current status of the job.
160
- #
161
- # @deprecated Use DeepL::Client#get_translation_memory_job instead.
162
-
163
- def find_job(job, options = {})
164
- DeepL::Requests::TranslationMemory::FindJob.new(@api, extract_job_id(job), options).request
165
- end
166
-
167
- ##
168
- # Polls a translation memory import or export job until it is finished, `sleep`ing between
169
- # the status queries, and returns the final status.
170
- #
171
- # Note that an import job keeps reporting `awaiting_input` for a while after its file has
172
- # been uploaded, because the API detects the upload asynchronously. That status is therefore
173
- # polled through like any other non-terminal one. A job whose file is never uploaded does not
174
- # finish on its own, so pass `timeout_s` when that is a possibility.
175
- #
176
- # @raise [DeepL::Exceptions::Error] If the job failed or expired, or if `timeout_s` elapsed
177
- # before the job finished.
178
- #
179
- # @param [String, DeepL::Resources::TranslationMemoryJob] job Job ID or object.
180
- # @param [Hash] options Additional options for the status queries.
181
- # @param [Numeric, nil] timeout_s Maximum time in seconds to wait for the job to finish. The
182
- # status is queried every five seconds; the last wait is cut
183
- # so that the call never waits past `timeout_s`.
184
- # @return [DeepL::Resources::TranslationMemoryJob] The finished job.
185
- #
186
- # @deprecated Use DeepL::Client#wait_until_translation_memory_job_done instead.
187
-
188
- def wait_until_job_done(job, options = {}, timeout_s: nil)
189
- deadline = timeout_s.nil? ? nil : monotonic_time + timeout_s
190
- job_status = find_job(job, options)
191
- until job_status.finished?
192
- interval = polling_interval_until(deadline, timeout_s)
193
- log_job_polling(interval)
194
- sleep(interval)
195
- job_status = find_job(job, options)
196
- end
197
- raise_job_error(job_status) if job_status.error?
198
-
199
- job_status
200
- end
201
-
202
- ##
203
- # Downloads the TMX file of a completed export job. The download URL is a pre-signed storage
204
- # URL outside of the DeepL API, so no authorization header is sent with this request.
205
- #
206
- # @raise [DeepL::Exceptions::Error] If the job carries no download URL, for example because
207
- # it has not completed yet.
208
- # @raise [DeepL::Exceptions::RequestError] If the storage URL replies with a non-2xx status:
209
- # the API error class for that status, e.g.
210
- # `AuthorizationFailed` for 401 and 403.
211
- # @raise [SystemCallError, IOError] If the file cannot be written.
212
- #
213
- # @param [DeepL::Resources::TranslationMemoryJob, String] job Completed export job carrying
214
- # the download URL, or the download URL itself.
215
- # @param [String] output_path Path to the file to write to. Will be overwritten if the file
216
- # already exists.
217
- #
218
- # @deprecated Use DeepL::Client#download_translation_memory_export instead.
219
-
220
- def download_export(job, output_path)
221
- DeepL::Requests::TranslationMemory::DownloadExport.new(@api, extract_download_url(job),
222
- output_path).request
223
- end
224
-
225
- ##
226
- # Imports a TMX file as a new translation memory: creates the import job, uploads the file
227
- # and waits for the processing to finish.
228
- #
229
- # @raise [DeepL::Exceptions::Error] If no file exists at `input_file_path` (before any request
230
- # is sent) or the import fails.
231
- # @raise [SystemCallError, IOError] If the file cannot be read.
232
- #
233
- # @param [String] input_file_path Path to the TMX file to import.
234
- # @param [String, nil] display_name Name of the resulting translation memory, defaults to the
235
- # file name.
236
- # @param [Numeric, nil] timeout_s Maximum time in seconds to wait for the import to finish.
237
- # Note that the API keeps reporting `awaiting_input` for a
238
- # while after the upload, so allow for a generous timeout.
239
- # @param [String, nil] content_type MIME type of the file, declared in the import job and sent
240
- # with the upload. Defaults to "application/xml".
241
- # @param [Hash, nil] extra_body_parameters Fields added to the body of the import job request
242
- # last; they replace fields of the same name.
243
- # @return [DeepL::Resources::TranslationMemoryJob] The finished import job, its result carries
244
- # the ID of the new translation memory.
245
- #
246
- # @deprecated Use DeepL::Client#import_translation_memory_from_filepath instead.
247
-
248
- def import_from_filepath(input_file_path, display_name: nil, timeout_s: nil,
249
- content_type: nil, extra_body_parameters: nil)
250
- check_input_file(input_file_path)
251
- file_content = read_input_file(input_file_path)
252
- created = create_import(File.basename(input_file_path), file_content.bytesize,
253
- content_type: content_type, display_name: display_name,
254
- extra_body_parameters: extra_body_parameters)
255
- upload_file(created, file_content, content_type: content_type)
256
- wait_until_job_done(created.job_id, timeout_s: timeout_s)
257
- end
258
-
259
- ##
260
- # Exports a translation memory to a TMX file: creates the export job, waits for it to finish
261
- # and writes the result to +output_path+.
262
- #
263
- # @raise [Errno::ENOENT] If the directory of `output_path` does not exist, checked before the
264
- # export job is created.
265
- # @raise [DeepL::Exceptions::Error] If the export fails.
266
- # @raise [SystemCallError, IOError] If the file cannot be written.
267
- #
268
- # @param [String, DeepL::Resources::TranslationMemory] translation_memory Translation memory
269
- # ID or object.
270
- # @param [String] output_path Path to the file to write to. Will be overwritten if the file
271
- # already exists.
272
- # @param [Numeric, nil] timeout_s Maximum time in seconds to wait for the export to finish.
273
- # @return [DeepL::Resources::TranslationMemoryJob] The finished export job.
274
- #
275
- # @deprecated Use DeepL::Client#export_translation_memory_to_filepath instead.
276
-
277
- def export_to_filepath(translation_memory, output_path, timeout_s: nil)
278
- check_output_directory(output_path)
279
- created = create_export(translation_memory)
280
- job = wait_until_job_done(created.job_id, timeout_s: timeout_s)
281
- download_export(job, output_path)
282
- job
283
- end
284
-
285
- private
286
-
287
- def extract_translation_memory_id(translation_memory)
288
- id = if translation_memory.is_a?(Resources::TranslationMemory)
289
- translation_memory.translation_memory_id
290
- else
291
- translation_memory
292
- end
293
- raise Exceptions::Error, 'Translation memory ID must not be empty' if blank?(id)
294
-
295
- id
296
- end
297
-
298
- def extract_job_id(job)
299
- id = job.is_a?(Resources::TranslationMemoryJob) ? job.job_id : job
300
- raise Exceptions::Error, 'Job ID must not be empty' if blank?(id)
301
-
302
- id
303
- end
304
-
305
- def extract_upload_url(translation_memory_import)
306
- if translation_memory_import.is_a?(Resources::TranslationMemoryImport)
307
- translation_memory_import.upload_url
308
- else
309
- translation_memory_import
310
- end
311
- end
312
-
313
- def extract_download_url(job)
314
- return job unless job.is_a?(Resources::TranslationMemoryJob)
315
-
316
- download_url = job.result&.download_url
317
- if blank?(download_url)
318
- raise Exceptions::Error, 'Translation memory export job has no download URL, ' \
319
- 'it may not have completed yet'
320
- end
321
-
322
- download_url
323
- end
324
-
325
- def blank?(value)
326
- value.nil? || value.empty?
327
- end
328
-
329
- # Until the next major version, the module-level API raises the error classes of v3.9.0 for
330
- # local file failures; DeepL::Client raises ArgumentError and wrapped errors.
331
- def check_input_file(input_file_path)
332
- return if File.exist?(input_file_path)
333
-
334
- message = "No file found at #{input_file_path}"
335
- raise ArgumentError, message if @api.client?
336
-
337
- raise Exceptions::Error, message
338
- end
339
-
340
- def read_input_file(input_file_path)
341
- File.binread(input_file_path)
342
- rescue SystemCallError, IOError => e
343
- raise e unless @api.client?
344
-
345
- raise Exceptions::Error, "Could not read #{input_file_path}: #{e.message}"
346
- end
347
-
348
- def check_output_directory(output_path)
349
- directory = File.dirname(output_path)
350
- return if File.directory?(directory)
351
-
352
- message = "Output directory #{directory} does not exist"
353
- raise Exceptions::Error, message if @api.client?
354
-
355
- raise Errno::ENOENT, message
356
- end
357
-
358
- def log_job_polling(interval)
359
- @api.configuration.logger&.info('Rechecking translation memory job status after sleeping ' \
360
- "for #{format('%.2f', interval)} seconds.")
361
- end
362
-
363
- def monotonic_time
364
- Process.clock_gettime(Process::CLOCK_MONOTONIC)
365
- end
366
-
367
- # The polling interval, cut to the time left until +deadline+ so that a wait never runs
368
- # past +timeout_s+.
369
- def polling_interval_until(deadline, timeout_s)
370
- return JOB_POLLING_INTERVAL_SECONDS if deadline.nil?
371
-
372
- remaining = deadline - monotonic_time
373
- raise_timeout_error(timeout_s) if remaining <= 0
374
-
375
- [JOB_POLLING_INTERVAL_SECONDS, remaining].min
376
- end
377
-
378
- def raise_timeout_error(timeout_s)
379
- raise Exceptions::Error,
380
- "Manual timeout of #{timeout_s}s exceeded for the translation memory job"
381
- end
382
-
383
- def raise_job_error(job_status)
384
- raise Exceptions::Error,
385
- "Error occurred during the translation memory #{job_status.operation}: " \
386
- "#{job_status.error_message || job_status.status}"
387
- end
388
- end
389
- end
data/license_checker.sh DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # Usage: ./license_checker.sh source_code_pattern
4
- # Example: ./license_checker.sh '*.rb'
5
- # This will search all .rb files, ignoring anything not tracked in your git tree
6
-
7
- git ls-files -z $1 | xargs -0 -n 10 -I{} sh -c 'RES=$(head -n 3 "{}" | grep "Copyright 20[0-9][0-9] DeepL SE (https://www.deepl.com)\|Copyright 20[0-9][0-9] Daniel Herzog"); if [ ! "${RES}" ] ; then echo "Lacking copyright header in" "{}" ; fi'
8
-
data/spec/fixtures.rb DELETED
@@ -1,33 +0,0 @@
1
- # Copyright 2026 DeepL SE (https://www.deepl.com)
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE file.
4
- # frozen_string_literal: true
5
-
6
- require 'tmpdir'
7
-
8
- # Fixtures shared by the offline and the real-API specs.
9
- module Fixtures
10
- EXAMPLE_TMX = <<~TMX
11
- <?xml version="1.0" encoding="UTF-8"?>
12
- <tmx version="1.4"><header creationtool="deepl-rb-spec" creationtoolversion="1"
13
- segtype="sentence" o-tmf="plain" adminlang="en" srclang="en" datatype="plaintext"/>
14
- <body><tu><tuv xml:lang="en"><seg>Segment number 1</seg></tuv>
15
- <tuv xml:lang="de"><seg>Segment Nummer 1</seg></tuv></tu></body></tmx>
16
- TMX
17
-
18
- # Every byte value, to check that downloads are written unchanged.
19
- BINARY_CONTENT = (0..255).map(&:chr).join.b.freeze
20
-
21
- # Writes an example .txt document in +dir+. Returns the input path and a free output path.
22
- def create_text_document(dir)
23
- input = File.join(dir, 'example_document.txt')
24
- File.write(input, 'proton beam')
25
- [input, File.join(dir, 'output_document.txt')]
26
- end
27
- end
28
-
29
- RSpec.shared_context 'with a temporary directory' do
30
- let(:temp_dir) { Dir.mktmpdir('deepl-rspec-') }
31
-
32
- after { FileUtils.remove_entry(temp_dir) }
33
- end