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/.gitlab-ci.yml
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
# Note: This GitLab CI configuration is used for internal testing, users can ignore it.
|
|
2
|
-
include:
|
|
3
|
-
- template: Security/SAST.gitlab-ci.yml
|
|
4
|
-
- project: '${CI_PROJECT_NAMESPACE}/ci-libs-for-client-libraries'
|
|
5
|
-
file:
|
|
6
|
-
- '/${CI_PROJECT_NAME}/.gitlab-ci.yml'
|
|
7
|
-
- project: 'deepl-org/deepl/devex/gitlab-ci-lib'
|
|
8
|
-
file:
|
|
9
|
-
- '/templates/.buildkit.yml'
|
|
10
|
-
- '/templates/.secret-detection.yml'
|
|
11
|
-
|
|
12
|
-
# Global --------------------------
|
|
13
|
-
|
|
14
|
-
workflow:
|
|
15
|
-
rules:
|
|
16
|
-
# The tag pipeline must run: that is where the registry publish job fires.
|
|
17
|
-
- if: $CI_COMMIT_TAG
|
|
18
|
-
# The release commit carries only the version and the changelog, both
|
|
19
|
-
# derived from commits that were already checked on the way in.
|
|
20
|
-
- if: $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
|
|
21
|
-
when: never
|
|
22
|
-
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
23
|
-
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
|
24
|
-
|
|
25
|
-
variables:
|
|
26
|
-
GITLAB_ADVANCED_SAST_ENABLED: 'true'
|
|
27
|
-
|
|
28
|
-
stages:
|
|
29
|
-
- install
|
|
30
|
-
- check
|
|
31
|
-
- test
|
|
32
|
-
- publish
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
before_script:
|
|
36
|
-
- ruby --version
|
|
37
|
-
- bundle install
|
|
38
|
-
|
|
39
|
-
# stage: install ----------------------
|
|
40
|
-
|
|
41
|
-
package:
|
|
42
|
-
stage: install
|
|
43
|
-
parallel:
|
|
44
|
-
matrix:
|
|
45
|
-
- DOCKER_IMAGE: 'ruby:2.7'
|
|
46
|
-
- DOCKER_IMAGE: 'ruby:3.2'
|
|
47
|
-
- DOCKER_IMAGE: 'ruby:3.3'
|
|
48
|
-
image:
|
|
49
|
-
name: ${DOCKER_IMAGE}
|
|
50
|
-
entrypoint: ['/builds/deepl/backend/oss-client-libs/deepl-ruby']
|
|
51
|
-
script:
|
|
52
|
-
- bundle exec rake build
|
|
53
|
-
artifacts:
|
|
54
|
-
paths:
|
|
55
|
-
- pkg/
|
|
56
|
-
|
|
57
|
-
# stage: check ----------------------
|
|
58
|
-
|
|
59
|
-
.rubocop_base:
|
|
60
|
-
stage: check
|
|
61
|
-
image:
|
|
62
|
-
name: ruby:2.7
|
|
63
|
-
entrypoint: ['/builds/deepl/backend/oss-client-libs/deepl-ruby']
|
|
64
|
-
variables:
|
|
65
|
-
HOME: /tmp
|
|
66
|
-
script: bundle exec rubocop
|
|
67
|
-
|
|
68
|
-
rubocop_scheduled:
|
|
69
|
-
extends: .rubocop_base
|
|
70
|
-
rules:
|
|
71
|
-
- if: $CI_PIPELINE_SOURCE == "schedule"
|
|
72
|
-
retry: 2
|
|
73
|
-
|
|
74
|
-
rubocop_manual:
|
|
75
|
-
extends: .rubocop_base
|
|
76
|
-
rules:
|
|
77
|
-
- if: $CI_PIPELINE_SOURCE != "schedule"
|
|
78
|
-
|
|
79
|
-
secret_detection:
|
|
80
|
-
extends: .secret-detection
|
|
81
|
-
stage: check
|
|
82
|
-
image: !reference [.secret-detection, image]
|
|
83
|
-
before_script:
|
|
84
|
-
- echo "overriding default before_script..."
|
|
85
|
-
rules:
|
|
86
|
-
- if: $CI_MERGE_REQUEST_ID
|
|
87
|
-
|
|
88
|
-
license_check:
|
|
89
|
-
stage: check
|
|
90
|
-
before_script:
|
|
91
|
-
- echo "overriding default before_script..."
|
|
92
|
-
script:
|
|
93
|
-
- ./license_checker.sh '*.rb' | tee license_check_output.txt
|
|
94
|
-
- '[ ! -s license_check_output.txt ]'
|
|
95
|
-
|
|
96
|
-
gitlab-advanced-sast:
|
|
97
|
-
stage: check
|
|
98
|
-
before_script:
|
|
99
|
-
- ''
|
|
100
|
-
rules:
|
|
101
|
-
- when: always
|
|
102
|
-
variables:
|
|
103
|
-
SAST_EXCLUDED_PATHS: '$DEFAULT_SAST_EXCLUDED_PATHS,/spec'
|
|
104
|
-
GIT_STRATEGY: clone
|
|
105
|
-
KUBERNETES_HELPER_MEMORY_LIMIT: 8Gi
|
|
106
|
-
SAST_SCANNER_ALLOWED_CLI_OPTS: --multi-core 8
|
|
107
|
-
|
|
108
|
-
semgrep-sast:
|
|
109
|
-
stage: check
|
|
110
|
-
before_script:
|
|
111
|
-
- ''
|
|
112
|
-
rules:
|
|
113
|
-
- when: always
|
|
114
|
-
variables:
|
|
115
|
-
SAST_EXCLUDED_PATHS: '$DEFAULT_SAST_EXCLUDED_PATHS,/spec'
|
|
116
|
-
GIT_STRATEGY: clone
|
|
117
|
-
KUBERNETES_MEMORY_LIMIT: 8Gi
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
# stage: test ----------------------
|
|
121
|
-
|
|
122
|
-
.test_offline_base:
|
|
123
|
-
stage: test
|
|
124
|
-
parallel:
|
|
125
|
-
matrix:
|
|
126
|
-
- DOCKER_IMAGE: 'ruby:2.7'
|
|
127
|
-
- DOCKER_IMAGE: 'ruby:3.2'
|
|
128
|
-
- DOCKER_IMAGE: 'ruby:3.3'
|
|
129
|
-
image:
|
|
130
|
-
name: ${DOCKER_IMAGE}
|
|
131
|
-
entrypoint: ['/builds/deepl/backend/oss-client-libs/deepl-ruby']
|
|
132
|
-
script:
|
|
133
|
-
- bundle exec rspec spec/offline --format progress --format RspecJunitFormatter --out rspec.xml
|
|
134
|
-
artifacts:
|
|
135
|
-
reports:
|
|
136
|
-
coverage_report:
|
|
137
|
-
coverage_format: cobertura
|
|
138
|
-
path: coverage/coverage.xml
|
|
139
|
-
junit:
|
|
140
|
-
- rspec.xml
|
|
141
|
-
when: always
|
|
142
|
-
|
|
143
|
-
test_offline_scheduled:
|
|
144
|
-
extends: .test_offline_base
|
|
145
|
-
rules:
|
|
146
|
-
- if: $CI_PIPELINE_SOURCE == "schedule"
|
|
147
|
-
retry: 2
|
|
148
|
-
|
|
149
|
-
test_offline_manual:
|
|
150
|
-
extends: .test_offline_base
|
|
151
|
-
rules:
|
|
152
|
-
- if: $CI_PIPELINE_SOURCE != "schedule"
|
|
153
|
-
|
|
154
|
-
# Every endpoint once against the real API; no retry, as a retry repeats every request.
|
|
155
|
-
.test_real_api_base:
|
|
156
|
-
stage: test
|
|
157
|
-
extends: .test
|
|
158
|
-
image:
|
|
159
|
-
name: ruby:3.3
|
|
160
|
-
entrypoint: ['/builds/deepl/backend/oss-client-libs/deepl-ruby']
|
|
161
|
-
script:
|
|
162
|
-
- bundle exec rspec spec/real_api --format progress --format RspecJunitFormatter --out rspec.xml
|
|
163
|
-
artifacts:
|
|
164
|
-
reports:
|
|
165
|
-
coverage_report:
|
|
166
|
-
coverage_format: cobertura
|
|
167
|
-
path: coverage/coverage.xml
|
|
168
|
-
junit:
|
|
169
|
-
- rspec.xml
|
|
170
|
-
when: always
|
|
171
|
-
|
|
172
|
-
test_real_api_scheduled:
|
|
173
|
-
extends: .test_real_api_base
|
|
174
|
-
rules:
|
|
175
|
-
- if: $CI_PIPELINE_SOURCE == "schedule"
|
|
176
|
-
|
|
177
|
-
test_real_api_manual:
|
|
178
|
-
extends: .test_real_api_base
|
|
179
|
-
rules:
|
|
180
|
-
- if: $CI_PIPELINE_SOURCE != "schedule"
|
|
181
|
-
|
|
182
|
-
# stage: publish ----------------------
|
|
183
|
-
|
|
184
|
-
gem push:
|
|
185
|
-
extends: .publish
|
|
186
|
-
stage: publish
|
|
187
|
-
image:
|
|
188
|
-
name: ruby:3.3
|
|
189
|
-
entrypoint: ['/builds/deepl/backend/oss-client-libs/deepl-ruby']
|
|
190
|
-
rules:
|
|
191
|
-
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
|
|
192
|
-
script:
|
|
193
|
-
# The committed gemspec keeps a hardcoded s.files list. Regenerate it from
|
|
194
|
-
# git ls-files; the version comes from lib/version.rb, written at release.
|
|
195
|
-
- bundle exec rake gemspec
|
|
196
|
-
- gem build deepl-rb.gemspec
|
|
197
|
-
- GEM_HOST_API_KEY="$RUBYGEM_PUBLISH_API_KEY" gem push "deepl-rb-${CI_COMMIT_TAG#v}.gem"
|
data/lib/deepl/deprecation.rb
DELETED
|
@@ -1,42 +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
|
-
# @api private
|
|
8
|
-
module Deprecation
|
|
9
|
-
@warned = {}
|
|
10
|
-
@mutex = Mutex.new
|
|
11
|
-
|
|
12
|
-
# Prints +message+ once per process for +key+, only while Ruby's deprecation warnings are on
|
|
13
|
-
# (+ruby -W:deprecated+). +uplevel+ 2 points the warning at the caller of the deprecated
|
|
14
|
-
# method.
|
|
15
|
-
def self.warn_once(key, message, uplevel: 2)
|
|
16
|
-
return unless enabled?
|
|
17
|
-
|
|
18
|
-
first = @mutex.synchronize { @warned[key] ? false : (@warned[key] = true) }
|
|
19
|
-
return unless first
|
|
20
|
-
|
|
21
|
-
if RUBY_VERSION >= '3.0'
|
|
22
|
-
Kernel.warn(message, uplevel: uplevel, category: :deprecated)
|
|
23
|
-
else
|
|
24
|
-
Kernel.warn(message, uplevel: uplevel)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Ruby 2.6 has no Warning.[] and prints no deprecation warnings.
|
|
29
|
-
def self.enabled?
|
|
30
|
-
Warning.respond_to?(:[]) && Warning[:deprecated]
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Like +warn_once+, but points the warning at the first caller outside the library, for
|
|
34
|
-
# deprecated options that are read deep inside a request.
|
|
35
|
-
def self.warn_once_at_caller(key, message)
|
|
36
|
-
lib_dir = File.expand_path('..', __dir__)
|
|
37
|
-
locations = caller_locations(1) || []
|
|
38
|
-
index = locations.index { |loc| !loc.absolute_path.to_s.start_with?(lib_dir) }
|
|
39
|
-
warn_once(key, message, uplevel: (index || 0) + 2)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
data/lib/deepl/document_api.rb
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
# Copyright 2024 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
|
-
module DeepL
|
|
7
|
-
class DocumentApi
|
|
8
|
-
def initialize(api, options = {})
|
|
9
|
-
@api = api
|
|
10
|
-
@options = options
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
# Uploads the file at the given +input_file_path+ to be translated from +source_lang+ into
|
|
15
|
-
# +target_lang+. The API interface is async, so you need to poll using the returned
|
|
16
|
-
# `DeepL::Resources::DocumentHandle` until the translation is finished, then you can download it
|
|
17
|
-
#
|
|
18
|
-
# @param [String] input_file_path File path to the file to be translated
|
|
19
|
-
# @param [String, nil] source_lang Source language to use for the translation. `nil` will cause
|
|
20
|
-
# automatic source langauge detection to be used. Must be
|
|
21
|
-
# formatted as ISO 639-1, 2-letter language codes.
|
|
22
|
-
# @param [String] target_lang Target language to use for the translation. Must be formatted as
|
|
23
|
-
# ISO 639-1, 2-letter language codes, plus a hyphen "-" with the
|
|
24
|
-
# variant identifier for languages with variants/dialects/... .
|
|
25
|
-
# @param [String, nil] filename The filename of the file, including its extension. Used to open
|
|
26
|
-
# the different kinds of documents (PDFs, etc). If nil, will use
|
|
27
|
-
# the filename of +input_file_path+.
|
|
28
|
-
# @param [Hash] options Additional (body) options for the upload. Notable glossary options:
|
|
29
|
-
# +:glossary+ (a glossary ID, `DeepL::Resources::Glossary` or
|
|
30
|
-
# `DeepL::Resources::MultilingualGlossary`; replaces the deprecated
|
|
31
|
-
# +:glossary_id+) or +:glossary_ids+ (an array of up to 5 glossary IDs
|
|
32
|
-
# or objects).
|
|
33
|
-
# +:glossary_ids+ requires +source_lang+ to be set, cannot be combined
|
|
34
|
-
# with +:glossary+ or +:glossary_id+, and raises `ArgumentError` if
|
|
35
|
-
# these rules are violated or more than 5 IDs are provided. Notable
|
|
36
|
-
# style/translation memory options (mirroring text translation):
|
|
37
|
-
# +:style_rule+ (a style rule ID string or a
|
|
38
|
-
# `DeepL::Resources::StyleRule` object),
|
|
39
|
-
# +:style_profile+ (a style profile ID string or a
|
|
40
|
-
# `DeepL::Resources::StyleProfile` object),
|
|
41
|
-
# +:translation_memory+ (a translation memory ID string or a
|
|
42
|
-
# `DeepL::Resources::TranslationMemory` object), and
|
|
43
|
-
# +:translation_memory_threshold+ (integer 0-100, recommended minimum 75).
|
|
44
|
-
# +:enable_watermark+ (boolean) adds a "Translated by DeepL" watermark;
|
|
45
|
-
# the API applies it to +docx+ and +pdf+ output only.
|
|
46
|
-
# @param [Hash] additional_headers Additional HTTP headers for the upload.
|
|
47
|
-
# @return [DeepL::Resources::DocumentHandle] Document handle for the uploaded document.
|
|
48
|
-
|
|
49
|
-
def upload(input_file_path, source_lang, target_lang, filename = nil, options = {},
|
|
50
|
-
additional_headers = {})
|
|
51
|
-
DeepL::Requests::Document::Upload.new(@api, input_file_path, source_lang, target_lang,
|
|
52
|
-
filename, options, additional_headers)
|
|
53
|
-
.request
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
##
|
|
57
|
-
# Queries the status of the translation of the document with the given +document_handle+.
|
|
58
|
-
#
|
|
59
|
-
# @param [DeepL::Resources::DocumentHandle] document_handle Handle returned by the `upload`
|
|
60
|
-
# method.
|
|
61
|
-
# @param [Hash] options Additional options for the upload.
|
|
62
|
-
# @param [Hash] additional_headers Additional HTTP headers for the status check.
|
|
63
|
-
# @return [DeepL::Resources::DocumentTranslationStatus] Status of the document translation.
|
|
64
|
-
|
|
65
|
-
def get_status(document_handle, options = {}, additional_headers = {})
|
|
66
|
-
DeepL::Requests::Document::GetStatus.new(@api, document_handle.document_id,
|
|
67
|
-
document_handle.document_key, options,
|
|
68
|
-
additional_headers).request
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
##
|
|
72
|
-
# Downloads the document identified by the +document_handle+ to +output_file+
|
|
73
|
-
#
|
|
74
|
-
# @param [DeepL::Resources::DocumentHandle] document_handle Handle returned by the `upload`
|
|
75
|
-
# method.
|
|
76
|
-
# @param [String] output_file Path to the file to write to. Will be overwritten if the file
|
|
77
|
-
# already exists.
|
|
78
|
-
# @return [DeepL::Resources::DocumentTranslationStatus] Status of the document translation.
|
|
79
|
-
|
|
80
|
-
def download(document_handle, output_file)
|
|
81
|
-
DeepL::Requests::Document::Download.new(@api, document_handle.document_id,
|
|
82
|
-
document_handle.document_key, output_file).request
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
##
|
|
86
|
-
# Translates a document with the DeepL API, `sleep`ing during waiting periods, and returns
|
|
87
|
-
# the number of bytes written once the translated document is downloaded. Polls until the
|
|
88
|
-
# translation is done or failed; the deprecated `max_doc_status_queries` limits the number of
|
|
89
|
-
# status requests if it is configured.
|
|
90
|
-
#
|
|
91
|
-
# @raise [DocumentTranslationError] If any error occurs during the process, also when the
|
|
92
|
-
# translation fails or is not done after `max_doc_status_queries`.
|
|
93
|
-
#
|
|
94
|
-
# @param [String] input_file Path to the file to be translated
|
|
95
|
-
# @param [String] output_file Path to the file to write to. Must not exist; if it does,
|
|
96
|
-
# DocumentTranslationError is raised and the file is kept.
|
|
97
|
-
# @param [String, nil] source_lang Source language to use for the translation. `nil` will cause
|
|
98
|
-
# automatic source langauge detection to be used. Must be
|
|
99
|
-
# formatted as ISO 639-1, 2-letter language codes.
|
|
100
|
-
# @param [String] target_lang Target language to use for the translation. Must be formatted as
|
|
101
|
-
# ISO 639-1, 2-letter language codes, plus a hyphen "-" with the
|
|
102
|
-
# variant identifier for languages with variants/dialects/... .
|
|
103
|
-
# @param [String, nil] filename The filename of the file, including its extension. Used to open
|
|
104
|
-
# the different kinds of documents (PDFs, etc). If nil, will use
|
|
105
|
-
# the filename of +input_file_path+.
|
|
106
|
-
# @param [Hash] options Additional options for the upload.
|
|
107
|
-
# @param [Hash] additional_headers Additional headers for the upload.
|
|
108
|
-
# @return [Integer] Number of bytes written
|
|
109
|
-
|
|
110
|
-
def translate_document(input_file, output_file, source_lang, target_lang, # rubocop:disable Metrics/MethodLength,Metrics/ParameterLists
|
|
111
|
-
filename = nil, options = {}, additional_headers = {})
|
|
112
|
-
if File.exist?(output_file)
|
|
113
|
-
raise Exceptions::DocumentTranslationError.new('File already exists at output path', nil)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
begin
|
|
117
|
-
handle = upload(input_file, source_lang, target_lang, filename, options,
|
|
118
|
-
additional_headers)
|
|
119
|
-
translate_document_wait_and_download(handle, output_file)
|
|
120
|
-
rescue StandardError => e
|
|
121
|
-
FileUtils.rm_f(output_file)
|
|
122
|
-
raise Exceptions::DocumentTranslationError.new(
|
|
123
|
-
"Error occurred during document translation: #{e.message}", handle, e
|
|
124
|
-
)
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
private
|
|
129
|
-
|
|
130
|
-
def translate_document_wait_and_download(document_handle, output_file)
|
|
131
|
-
doc_status = Utils::DocumentPoller.wait_until_finished(
|
|
132
|
-
@api, document_handle, max_queries: @api.configuration.max_doc_status_queries
|
|
133
|
-
)
|
|
134
|
-
unless doc_status.done?
|
|
135
|
-
raise Exceptions::DocumentTranslationError.new(not_done_message(doc_status),
|
|
136
|
-
document_handle)
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
download(document_handle, output_file)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def not_done_message(doc_status)
|
|
143
|
-
if doc_status.error?
|
|
144
|
-
"Exception when querying document status #{doc_status.error_message}"
|
|
145
|
-
else
|
|
146
|
-
"Document translation not done after max_doc_status_queries (#{doc_status.status})"
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
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
|
-
module Exceptions
|
|
8
|
-
# @deprecated Only the module-level API raises it, from
|
|
9
|
-
# +DeepL::Resources::Language#supports_formality?+ for a source language; DeepL::Client
|
|
10
|
-
# returns +nil+ instead.
|
|
11
|
-
class NotSupported < Error
|
|
12
|
-
def initialize(msg = 'The feature is not supported')
|
|
13
|
-
Deprecation.warn_once('DeepL::Exceptions::NotSupported',
|
|
14
|
-
'[DEPRECATION] DeepL::Exceptions::NotSupported is deprecated, ' \
|
|
15
|
-
'only the module-level API raises it.')
|
|
16
|
-
super
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
data/lib/deepl/glossary_api.rb
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
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
|
-
class GlossaryApi
|
|
8
|
-
def initialize(api, options = {})
|
|
9
|
-
@api = api
|
|
10
|
-
@options = options
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def create(name, source_lang, target_lang, entries, options = {})
|
|
14
|
-
DeepL::Requests::Glossary::Create.new(@api, name, source_lang, target_lang, entries, options)
|
|
15
|
-
.request
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def destroy(glossary_id, options = {})
|
|
19
|
-
DeepL::Requests::Glossary::Destroy.new(@api, glossary_id, options).request
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def entries(glossary_id, options = {})
|
|
23
|
-
DeepL::Requests::Glossary::Entries.new(@api, glossary_id, options).request
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def find(glossary_id, options = {})
|
|
27
|
-
DeepL::Requests::Glossary::Find.new(@api, glossary_id, options).request
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def language_pairs(options = {})
|
|
31
|
-
DeepL::Requests::Glossary::LanguagePairs.new(@api, options).request
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def list(options = {})
|
|
35
|
-
DeepL::Requests::Glossary::List.new(@api, options).request
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
data/lib/deepl/style_rule_api.rb
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 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 style rule methods of DeepL::Client instead.
|
|
8
|
-
class StyleRuleApi
|
|
9
|
-
def initialize(api, options = {})
|
|
10
|
-
@api = api
|
|
11
|
-
@options = options
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# @deprecated Use DeepL::Client#get_all_style_rules instead.
|
|
15
|
-
def list(options = {})
|
|
16
|
-
DeepL::Requests::StyleRule::List.new(@api, options).request
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# @deprecated Use DeepL::Client#create_style_rule instead.
|
|
20
|
-
def create(name, language, options = {})
|
|
21
|
-
DeepL::Requests::StyleRule::Create.new(@api, name, language, options).request
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# @deprecated Use DeepL::Client#get_style_rule instead.
|
|
25
|
-
def find(style_id, options = {})
|
|
26
|
-
DeepL::Requests::StyleRule::Find.new(@api, style_id, options).request
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# @deprecated Use DeepL::Client#update_style_rule_name instead.
|
|
30
|
-
def update_name(style_id, name, options = {})
|
|
31
|
-
DeepL::Requests::StyleRule::Update.new(@api, style_id, name, options).request
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# @deprecated Use DeepL::Client#delete_style_rule instead.
|
|
35
|
-
def destroy(style_id, options = {})
|
|
36
|
-
DeepL::Requests::StyleRule::Destroy.new(@api, style_id, options).request
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# @deprecated Use DeepL::Client#update_style_rule_configured_rules instead.
|
|
40
|
-
def update_configured_rules(style_id, configured_rules, options = {})
|
|
41
|
-
DeepL::Requests::StyleRule::UpdateConfiguredRules.new(@api, style_id, configured_rules,
|
|
42
|
-
options).request
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# @deprecated Use DeepL::Client#create_style_rule_custom_instruction instead.
|
|
46
|
-
def create_custom_instruction(style_id, label, prompt, source_language = nil, options = {})
|
|
47
|
-
DeepL::Requests::StyleRule::CreateCustomInstruction.new(@api, style_id, label, prompt,
|
|
48
|
-
source_language, options).request
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# @deprecated Use DeepL::Client#get_style_rule_custom_instruction instead.
|
|
52
|
-
def find_custom_instruction(style_id, instruction_id, options = {})
|
|
53
|
-
DeepL::Requests::StyleRule::FindCustomInstruction.new(@api, style_id, instruction_id,
|
|
54
|
-
options).request
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# @deprecated Use DeepL::Client#update_style_rule_custom_instruction instead.
|
|
58
|
-
def update_custom_instruction(style_id, instruction_id, label,
|
|
59
|
-
prompt, source_language = nil,
|
|
60
|
-
options = {})
|
|
61
|
-
DeepL::Requests::StyleRule::UpdateCustomInstruction.new(@api, style_id, instruction_id,
|
|
62
|
-
label, prompt, source_language,
|
|
63
|
-
options).request
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# @deprecated Use DeepL::Client#delete_style_rule_custom_instruction instead.
|
|
67
|
-
def destroy_custom_instruction(style_id, instruction_id, options = {})
|
|
68
|
-
DeepL::Requests::StyleRule::DestroyCustomInstruction.new(@api, style_id, instruction_id,
|
|
69
|
-
options).request
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|