deepl-rb 3.9.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 (215) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +27 -1
  3. data/CHANGELOG.md +741 -18
  4. data/Gemfile +4 -0
  5. data/README.md +1001 -327
  6. data/Rakefile +29 -7
  7. data/VERSION +1 -1
  8. data/deepl-rb.gemspec +75 -88
  9. data/lib/deepl/admin_client.rb +208 -0
  10. data/lib/deepl/api.rb +18 -8
  11. data/lib/deepl/app_info.rb +19 -0
  12. data/lib/deepl/client.rb +1284 -0
  13. data/lib/deepl/configuration.rb +27 -32
  14. data/lib/deepl/constants/admin_usage_group_by.rb +13 -0
  15. data/lib/deepl/constants/custom_tag_usage_aggregate_by.rb +13 -0
  16. data/lib/deepl/constants/document_status_code.rb +17 -0
  17. data/lib/deepl/constants/language_include.rb +17 -0
  18. data/lib/deepl/constants/language_resource_name.rb +21 -0
  19. data/lib/deepl/constants/tag_handling_version.rb +14 -0
  20. data/lib/deepl/exceptions/authorization_failed.rb +1 -1
  21. data/lib/deepl/exceptions/bad_request.rb +1 -3
  22. data/lib/deepl/exceptions/connection_error.rb +40 -0
  23. data/lib/deepl/exceptions/document_not_ready_error.rb +17 -0
  24. data/lib/deepl/exceptions/document_translation_error.rb +17 -1
  25. data/lib/deepl/exceptions/error.rb +13 -1
  26. data/lib/deepl/exceptions/limit_exceeded.rb +1 -1
  27. data/lib/deepl/exceptions/not_found.rb +8 -3
  28. data/lib/deepl/exceptions/quota_exceeded.rb +1 -1
  29. data/lib/deepl/exceptions/request_entity_too_large.rb +1 -2
  30. data/lib/deepl/exceptions/request_error.rb +26 -2
  31. data/lib/deepl/exceptions/server_error.rb +9 -2
  32. data/lib/deepl/exceptions/translation_memory_job_error.rb +32 -0
  33. data/lib/deepl/exceptions/validation_error.rb +15 -0
  34. data/lib/deepl/requests/admin/base.rb +94 -0
  35. data/lib/deepl/requests/admin/create_developer_key.rb +38 -0
  36. data/lib/deepl/requests/admin/custom_tag_usage_analytics.rb +38 -0
  37. data/lib/deepl/requests/admin/list_developer_keys.rb +28 -0
  38. data/lib/deepl/requests/admin/update_developer_key.rb +35 -0
  39. data/lib/deepl/requests/admin/usage_analytics.rb +36 -0
  40. data/lib/deepl/requests/base.rb +313 -65
  41. data/lib/deepl/requests/correct.rb +51 -0
  42. data/lib/deepl/requests/document/download.rb +11 -3
  43. data/lib/deepl/requests/document/get_status.rb +2 -2
  44. data/lib/deepl/requests/document/upload.rb +56 -20
  45. data/lib/deepl/requests/glossary/base.rb +30 -0
  46. data/lib/deepl/requests/glossary/create.rb +18 -18
  47. data/lib/deepl/requests/glossary/destroy.rb +4 -16
  48. data/lib/deepl/requests/glossary/entries.rb +6 -14
  49. data/lib/deepl/requests/glossary/find.rb +3 -13
  50. data/lib/deepl/requests/glossary/language_pairs.rb +22 -6
  51. data/lib/deepl/requests/glossary/list.rb +2 -2
  52. data/lib/deepl/requests/language_resources.rb +41 -0
  53. data/lib/deepl/requests/languages.rb +25 -6
  54. data/lib/deepl/requests/languages_for_resource.rb +56 -0
  55. data/lib/deepl/requests/multilingual_glossary/create.rb +45 -0
  56. data/lib/deepl/requests/multilingual_glossary/destroy.rb +36 -0
  57. data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +55 -0
  58. data/lib/deepl/requests/multilingual_glossary/entries.rb +68 -0
  59. data/lib/deepl/requests/multilingual_glossary/find.rb +35 -0
  60. data/lib/deepl/requests/multilingual_glossary/helpers.rb +71 -0
  61. data/lib/deepl/requests/multilingual_glossary/list.rb +39 -0
  62. data/lib/deepl/requests/multilingual_glossary/replace_dictionary.rb +41 -0
  63. data/lib/deepl/requests/multilingual_glossary/update.rb +40 -0
  64. data/lib/deepl/requests/rephrase.rb +8 -10
  65. data/lib/deepl/requests/spoken_terms/create.rb +42 -0
  66. data/lib/deepl/requests/spoken_terms/destroy.rb +36 -0
  67. data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +42 -0
  68. data/lib/deepl/requests/spoken_terms/entries.rb +47 -0
  69. data/lib/deepl/requests/spoken_terms/find.rb +35 -0
  70. data/lib/deepl/requests/spoken_terms/helpers.rb +74 -0
  71. data/lib/deepl/requests/spoken_terms/list.rb +35 -0
  72. data/lib/deepl/requests/spoken_terms/replace_term_list.rb +41 -0
  73. data/lib/deepl/requests/spoken_terms/update.rb +40 -0
  74. data/lib/deepl/requests/style_profile/base.rb +83 -0
  75. data/lib/deepl/requests/style_profile/create.rb +40 -0
  76. data/lib/deepl/requests/style_profile/destroy.rb +34 -0
  77. data/lib/deepl/requests/style_profile/find.rb +33 -0
  78. data/lib/deepl/requests/style_profile/list.rb +43 -0
  79. data/lib/deepl/requests/style_profile/update.rb +35 -0
  80. data/lib/deepl/requests/style_rule/create.rb +24 -0
  81. data/lib/deepl/requests/style_rule/create_custom_instruction.rb +11 -2
  82. data/lib/deepl/requests/style_rule/destroy.rb +4 -2
  83. data/lib/deepl/requests/style_rule/destroy_custom_instruction.rb +5 -3
  84. data/lib/deepl/requests/style_rule/find.rb +4 -2
  85. data/lib/deepl/requests/style_rule/find_custom_instruction.rb +5 -3
  86. data/lib/deepl/requests/style_rule/helpers.rb +44 -0
  87. data/lib/deepl/requests/style_rule/list.rb +3 -1
  88. data/lib/deepl/requests/style_rule/update.rb +5 -2
  89. data/lib/deepl/requests/style_rule/update_configured_rules.rb +4 -2
  90. data/lib/deepl/requests/style_rule/update_custom_instruction.rb +7 -3
  91. data/lib/deepl/requests/translate.rb +43 -27
  92. data/lib/deepl/requests/translation_memory/base.rb +1 -4
  93. data/lib/deepl/requests/translation_memory/create_export.rb +7 -2
  94. data/lib/deepl/requests/translation_memory/create_import.rb +11 -1
  95. data/lib/deepl/requests/translation_memory/destroy.rb +1 -1
  96. data/lib/deepl/requests/translation_memory/find.rb +1 -1
  97. data/lib/deepl/requests/translation_memory/find_job.rb +1 -1
  98. data/lib/deepl/requests/translation_memory/list.rb +4 -3
  99. data/lib/deepl/requests/translation_memory/segments.rb +5 -4
  100. data/lib/deepl/requests/translation_memory/storage_base.rb +37 -9
  101. data/lib/deepl/requests/translation_memory/upload_file.rb +1 -1
  102. data/lib/deepl/requests/usage.rb +28 -1
  103. data/lib/deepl/requests/write_improvements.rb +42 -0
  104. data/lib/deepl/resources/admin_usage_report.rb +73 -0
  105. data/lib/deepl/resources/custom_tag_usage_report.rb +59 -0
  106. data/lib/deepl/resources/developer_key.rb +57 -0
  107. data/lib/deepl/resources/document_handle.rb +8 -34
  108. data/lib/deepl/resources/document_translation_status.rb +14 -7
  109. data/lib/deepl/resources/language.rb +5 -3
  110. data/lib/deepl/resources/language_resource.rb +57 -0
  111. data/lib/deepl/resources/language_support.rb +56 -0
  112. data/lib/deepl/resources/multilingual_glossary.rb +112 -0
  113. data/lib/deepl/resources/spoken_terms.rb +61 -0
  114. data/lib/deepl/resources/style_profile.rb +44 -0
  115. data/lib/deepl/resources/style_rule.rb +4 -23
  116. data/lib/deepl/resources/text.rb +18 -2
  117. data/lib/deepl/resources/translation_memory.rb +8 -2
  118. data/lib/deepl/resources/translation_memory_import.rb +1 -1
  119. data/lib/deepl/resources/translation_memory_job.rb +26 -7
  120. data/lib/deepl/resources/translation_memory_segments.rb +8 -6
  121. data/lib/deepl/resources/usage.rb +61 -5
  122. data/lib/deepl/utils/client_builder.rb +89 -0
  123. data/lib/deepl/utils/document_poller.rb +70 -0
  124. data/lib/deepl/utils/exception_builder.rb +3 -2
  125. data/lib/deepl/utils/glossary_entries.rb +30 -0
  126. data/lib/deepl/utils/http_client_builder.rb +116 -0
  127. data/lib/deepl/utils/number_parser.rb +34 -0
  128. data/lib/deepl/utils/output_path.rb +25 -0
  129. data/lib/deepl/utils/term_validator.rb +33 -0
  130. data/lib/deepl/utils/time_parser.rb +14 -0
  131. data/lib/deepl/utils/translation_memory_operations.rb +230 -0
  132. data/lib/deepl.rb +68 -108
  133. data/lib/http_client_options.rb +21 -1
  134. data/lib/version.rb +1 -1
  135. data/upgrading_to_v4.md +374 -0
  136. metadata +84 -85
  137. data/.circleci/config.yml +0 -27
  138. data/.github/workflows/add_issues_to_kanban.yml +0 -16
  139. data/.gitlab-ci.yml +0 -179
  140. data/lib/deepl/document_api.rb +0 -131
  141. data/lib/deepl/exceptions/not_supported.rb +0 -14
  142. data/lib/deepl/glossary_api.rb +0 -38
  143. data/lib/deepl/style_rule_api.rb +0 -61
  144. data/lib/deepl/translation_memory_api.rb +0 -309
  145. data/license_checker.sh +0 -8
  146. data/spec/api/api_spec.rb +0 -20
  147. data/spec/api/configuration_spec.rb +0 -122
  148. data/spec/api/deepl_spec.rb +0 -262
  149. data/spec/constants/constants_spec.rb +0 -158
  150. data/spec/integration_tests/document_api_spec.rb +0 -211
  151. data/spec/integration_tests/document_error_paths_spec.rb +0 -33
  152. data/spec/integration_tests/glossary_api_spec.rb +0 -114
  153. data/spec/integration_tests/glossary_error_paths_spec.rb +0 -107
  154. data/spec/integration_tests/integration_test_utils.rb +0 -178
  155. data/spec/integration_tests/languages_api_spec.rb +0 -54
  156. data/spec/integration_tests/languages_error_paths_spec.rb +0 -25
  157. data/spec/integration_tests/rephrase_api_spec.rb +0 -90
  158. data/spec/integration_tests/rephrase_error_paths_spec.rb +0 -53
  159. data/spec/integration_tests/smoke_test_spec.rb +0 -24
  160. data/spec/integration_tests/style_rule_api_spec.rb +0 -117
  161. data/spec/integration_tests/style_rule_error_paths_spec.rb +0 -45
  162. data/spec/integration_tests/translate_api_spec.rb +0 -117
  163. data/spec/integration_tests/translate_error_paths_spec.rb +0 -48
  164. data/spec/integration_tests/translation_memory_api_spec.rb +0 -244
  165. data/spec/integration_tests/translation_memory_error_paths_spec.rb +0 -87
  166. data/spec/integration_tests/usage_api_spec.rb +0 -29
  167. data/spec/integration_tests/usage_error_paths_spec.rb +0 -18
  168. data/spec/requests/document/upload_spec.rb +0 -130
  169. data/spec/requests/extra_body_parameters_types_spec.rb +0 -82
  170. data/spec/requests/glossary/create_spec.rb +0 -44
  171. data/spec/requests/glossary/destroy_spec.rb +0 -27
  172. data/spec/requests/glossary/entries_spec.rb +0 -27
  173. data/spec/requests/glossary/find_spec.rb +0 -28
  174. data/spec/requests/glossary/language_pairs_spec.rb +0 -27
  175. data/spec/requests/glossary/list_spec.rb +0 -27
  176. data/spec/requests/languages_spec.rb +0 -27
  177. data/spec/requests/rephrase_spec.rb +0 -46
  178. data/spec/requests/style_rule/create_custom_instruction_spec.rb +0 -30
  179. data/spec/requests/style_rule/create_spec.rb +0 -29
  180. data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +0 -28
  181. data/spec/requests/style_rule/destroy_spec.rb +0 -27
  182. data/spec/requests/style_rule/find_custom_instruction_spec.rb +0 -29
  183. data/spec/requests/style_rule/find_spec.rb +0 -28
  184. data/spec/requests/style_rule/list_spec.rb +0 -27
  185. data/spec/requests/style_rule/update_configured_rules_spec.rb +0 -31
  186. data/spec/requests/style_rule/update_custom_instruction_spec.rb +0 -32
  187. data/spec/requests/style_rule/update_spec.rb +0 -29
  188. data/spec/requests/translate_spec.rb +0 -338
  189. data/spec/requests/translation_memory/create_export_spec.rb +0 -37
  190. data/spec/requests/translation_memory/create_import_spec.rb +0 -61
  191. data/spec/requests/translation_memory/destroy_spec.rb +0 -36
  192. data/spec/requests/translation_memory/download_export_spec.rb +0 -54
  193. data/spec/requests/translation_memory/find_job_spec.rb +0 -37
  194. data/spec/requests/translation_memory/find_spec.rb +0 -36
  195. data/spec/requests/translation_memory/list_spec.rb +0 -27
  196. data/spec/requests/translation_memory/segments_spec.rb +0 -58
  197. data/spec/requests/translation_memory/upload_file_spec.rb +0 -55
  198. data/spec/requests/usage_spec.rb +0 -27
  199. data/spec/resources/custom_instruction_spec.rb +0 -32
  200. data/spec/resources/glossary_spec.rb +0 -38
  201. data/spec/resources/language_pair_spec.rb +0 -23
  202. data/spec/resources/language_spec.rb +0 -45
  203. data/spec/resources/style_rule_spec.rb +0 -68
  204. data/spec/resources/text_spec.rb +0 -23
  205. data/spec/resources/translation_memory_export_spec.rb +0 -38
  206. data/spec/resources/translation_memory_import_spec.rb +0 -30
  207. data/spec/resources/translation_memory_job_spec.rb +0 -109
  208. data/spec/resources/translation_memory_segments_spec.rb +0 -78
  209. data/spec/resources/translation_memory_spec.rb +0 -52
  210. data/spec/resources/usage_spec.rb +0 -35
  211. data/spec/spec_helper.rb +0 -62
  212. data/spec/support/live_mock_server.rb +0 -12
  213. data/spec/support/managed_glossary.rb +0 -65
  214. data/spec/support/managed_style_rule.rb +0 -17
  215. data/spec/support/managed_translation_memory.rb +0 -55
@@ -1,16 +0,0 @@
1
- name: Add bugs to bugs project
2
-
3
- on:
4
- issues:
5
- types:
6
- - opened
7
-
8
- jobs:
9
- add-to-project:
10
- name: Add issue to project
11
- runs-on: ubuntu-latest
12
- steps:
13
- - uses: actions/add-to-project@v0.5.0
14
- with:
15
- project-url: https://github.com/orgs/DeepLcom/projects/1
16
- github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
data/.gitlab-ci.yml DELETED
@@ -1,179 +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
- - '/templates/.gitlab-release.yml'
12
-
13
- # Global --------------------------
14
-
15
- workflow:
16
- rules:
17
- - if: $CI_PIPELINE_SOURCE == "merge_request_event"
18
- - if: $CI_COMMIT_TAG
19
- - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
20
-
21
- variables:
22
- GITLAB_ADVANCED_SAST_ENABLED: 'true'
23
-
24
- stages:
25
- - install
26
- - check
27
- - test
28
- - publish # Only for internal tracking
29
-
30
-
31
- before_script:
32
- - ruby --version
33
- - bundle install
34
-
35
- # stage: install ----------------------
36
-
37
- package:
38
- stage: install
39
- parallel:
40
- matrix:
41
- - DOCKER_IMAGE: 'ruby:2.7'
42
- - DOCKER_IMAGE: 'ruby:3.2'
43
- - DOCKER_IMAGE: 'ruby:3.3'
44
- image:
45
- name: ${DOCKER_IMAGE}
46
- entrypoint: ['/builds/deepl/backend/oss-client-libs/deepl-ruby']
47
- script:
48
- - bundle exec rake build
49
- artifacts:
50
- paths:
51
- - pkg/
52
-
53
- # stage: check ----------------------
54
-
55
- .rubocop_base:
56
- stage: check
57
- image:
58
- name: ruby:2.7
59
- entrypoint: ['/builds/deepl/backend/oss-client-libs/deepl-ruby']
60
- variables:
61
- HOME: /tmp
62
- script: bundle exec rubocop
63
-
64
- rubocop_scheduled:
65
- extends: .rubocop_base
66
- rules:
67
- - if: $CI_PIPELINE_SOURCE == "schedule"
68
- retry: 2
69
-
70
- rubocop_manual:
71
- extends: .rubocop_base
72
- rules:
73
- - if: $CI_PIPELINE_SOURCE != "schedule"
74
-
75
- secret_detection:
76
- extends: .secret-detection
77
- stage: check
78
- image: !reference [.secret-detection, image]
79
- before_script:
80
- - echo "overriding default before_script..."
81
- rules:
82
- - if: $CI_MERGE_REQUEST_ID
83
-
84
- license_check:
85
- stage: check
86
- before_script:
87
- - echo "overriding default before_script..."
88
- script:
89
- - ./license_checker.sh '*.rb' | tee license_check_output.txt
90
- - '[ ! -s license_check_output.txt ]'
91
-
92
- gitlab-advanced-sast:
93
- stage: check
94
- before_script:
95
- - ''
96
- rules:
97
- - when: always
98
- variables:
99
- SAST_EXCLUDED_PATHS: '$DEFAULT_SAST_EXCLUDED_PATHS,/spec'
100
- GIT_STRATEGY: clone
101
- KUBERNETES_HELPER_MEMORY_LIMIT: 8Gi
102
- SAST_SCANNER_ALLOWED_CLI_OPTS: --multi-core 8
103
-
104
- semgrep-sast:
105
- stage: check
106
- before_script:
107
- - ''
108
- rules:
109
- - when: always
110
- variables:
111
- SAST_EXCLUDED_PATHS: '$DEFAULT_SAST_EXCLUDED_PATHS,/spec'
112
- GIT_STRATEGY: clone
113
- KUBERNETES_MEMORY_LIMIT: 8Gi
114
-
115
-
116
- # stage: test ----------------------
117
-
118
- .test_base:
119
- stage: test
120
- extends: .test
121
- variables:
122
- VALIDATE_REQUESTS_FOR_DEEPL_MOCK: '1'
123
- VALIDATE_RESPONSES_FOR_DEEPL_MOCK: '1'
124
- parallel:
125
- matrix:
126
- - DOCKER_IMAGE: 'ruby:2.7'
127
- - DOCKER_IMAGE: 'ruby:3.2'
128
- - DOCKER_IMAGE: 'ruby:3.3'
129
- - DOCKER_IMAGE: 'ruby:2.7'
130
- USE_MOCK_SERVER: "use mock server"
131
- - DOCKER_IMAGE: 'ruby:3.2'
132
- USE_MOCK_SERVER: "use mock server"
133
- - DOCKER_IMAGE: 'ruby:3.3'
134
- USE_MOCK_SERVER: "use mock server"
135
- image:
136
- name: ${DOCKER_IMAGE}
137
- entrypoint: ['/builds/deepl/backend/oss-client-libs/deepl-ruby']
138
- script:
139
- - >
140
- if [[ ! -z "${USE_MOCK_SERVER}" ]]; then
141
- echo "Using mock server"
142
- export DEEPL_SERVER_URL=http://deepl-mock:3000
143
- export DEEPL_MOCK_SERVER_PORT=3000
144
- export DEEPL_PROXY_URL=http://deepl-mock:3001
145
- export DEEPL_MOCK_PROXY_SERVER_PORT=3001
146
- fi
147
- - bundle exec rake test
148
- - bundle exec rspec --format RspecJunitFormatter --out rspec.xml
149
- artifacts:
150
- reports:
151
- coverage_report:
152
- coverage_format: cobertura
153
- path: coverage/coverage.xml
154
- junit:
155
- - rspec.xml
156
- when: always
157
-
158
- test_scheduled:
159
- extends: .test_base
160
- rules:
161
- - if: $CI_PIPELINE_SOURCE == "schedule"
162
- retry: 2
163
-
164
- test_manual:
165
- stage: test
166
- extends: .test_base
167
- rules:
168
- - if: $CI_PIPELINE_SOURCE != "schedule"
169
-
170
- # stage: publish ----------------------
171
-
172
- gitlab release:
173
- stage: publish
174
- image: registry.gitlab.com/gitlab-org/release-cli:latest
175
- extends: .create_gitlab_release
176
- before_script:
177
- - echo "overriding default before_script..."
178
- rules:
179
- - if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
@@ -1,131 +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_id+ (a single glossary ID) or +:glossary_ids+ (an array of
30
- # up to 5 glossary IDs, as strings or `DeepL::Resources::Glossary`
31
- # objects). +:glossary_ids+ requires +source_lang+ to be set, cannot be
32
- # combined with +:glossary_id+, and raises `ArgumentError` if these rules
33
- # are violated or more than 5 IDs are provided. Notable style/translation
34
- # memory options (mirroring text translation): +:style_rule+ (a style rule
35
- # ID string or a `DeepL::Resources::StyleRule` object),
36
- # +:translation_memory+ (a translation memory ID string or a
37
- # `DeepL::Resources::TranslationMemory` object), and
38
- # +:translation_memory_threshold+ (integer 0-100, recommended minimum 75).
39
- # @param [Hash] additional_headers Additional HTTP headers for the upload.
40
- # @return [DeepL::Resources::DocumentHandle] Document handle for the uploaded document.
41
-
42
- def upload(input_file_path, source_lang, target_lang, filename = nil, options = {},
43
- additional_headers = {})
44
- DeepL::Requests::Document::Upload.new(@api, input_file_path, source_lang, target_lang,
45
- filename, options, additional_headers)
46
- .request
47
- end
48
-
49
- ##
50
- # Queries the status of the translation of the document with the given +document_handle+.
51
- #
52
- # @param [DeepL::Resources::DocumentHandle] document_handle Handle returned by the `upload`
53
- # method.
54
- # @param [Hash] options Additional options for the upload.
55
- # @param [Hash] additional_headers Additional HTTP headers for the status check.
56
- # @return [DeepL::Resources::DocumentTranslationStatus] Status of the document translation.
57
-
58
- def get_status(document_handle, options = {}, additional_headers = {})
59
- DeepL::Requests::Document::GetStatus.new(@api, document_handle.document_id,
60
- document_handle.document_key, options,
61
- additional_headers).request
62
- end
63
-
64
- ##
65
- # Downloads the document identified by the +document_handle+ to +output_file+
66
- #
67
- # @param [DeepL::Resources::DocumentHandle] document_handle Handle returned by the `upload`
68
- # method.
69
- # @param [String] output_file Path to the file to write to. Will be overwritten if the file
70
- # already exists.
71
- # @return [DeepL::Resources::DocumentTranslationStatus] Status of the document translation.
72
-
73
- def download(document_handle, output_file)
74
- DeepL::Requests::Document::Download.new(@api, document_handle.document_id,
75
- document_handle.document_key, output_file).request
76
- end
77
-
78
- ##
79
- # Translates a document with the DeepL API, `sleep`ing during waiting periods. Returns the
80
- # status that was queried last. This can be either because the document translation terminated
81
- # (successfully or with an error) or because the maximum number of status requests have been
82
- # made. See the parameter `max_doc_status_queries` for details.
83
- #
84
- # @raise [DocumentTranslationError] If any error occurs during the process.
85
- #
86
- # @param [String] input_file Path to the file to be translated
87
- # @param [String] output_file Path to the file to write to. Will be overwritten if the file
88
- # already exists.
89
- # @param [String, nil] source_lang Source language to use for the translation. `nil` will cause
90
- # automatic source langauge detection to be used. Must be
91
- # formatted as ISO 639-1, 2-letter language codes.
92
- # @param [String] target_lang Target language to use for the translation. Must be formatted as
93
- # ISO 639-1, 2-letter language codes, plus a hyphen "-" with the
94
- # variant identifier for languages with variants/dialects/... .
95
- # @param [String, nil] filename The filename of the file, including its extension. Used to open
96
- # the different kinds of documents (PDFs, etc). If nil, will use
97
- # the filename of +input_file_path+.
98
- # @param [Hash] options Additional options for the upload.
99
- # @param [Hash] additional_headers Additional headers for the upload.
100
- # @return [DeepL::Resources::DocumentTranslationStatus] Status of the document translation.
101
-
102
- def translate_document(input_file, output_file, source_lang, target_lang, # rubocop:disable Metrics/MethodLength,Metrics/ParameterLists
103
- filename = nil, options = {}, additional_headers = {})
104
- raise IOError 'File already exists at output path' if File.exist?(output_file)
105
-
106
- begin
107
- handle = upload(input_file, source_lang, target_lang, filename, options,
108
- additional_headers)
109
- translate_document_wait_and_download(handle, output_file)
110
- rescue StandardError => e
111
- FileUtils.rm_f(output_file)
112
- raise Exceptions::DocumentTranslationError.new(
113
- "Error occurred during document translation: #{e.message}", handle
114
- )
115
- end
116
- end
117
-
118
- private
119
-
120
- def translate_document_wait_and_download(document_handle, output_file)
121
- doc_status = document_handle.wait_until_document_translation_finished
122
- if doc_status.error?
123
- raise Exceptions::DocumentTranslationError.new(
124
- "Exception when querying document status #{doc_status.error_message}", document_handle
125
- )
126
- else
127
- download(document_handle, output_file)
128
- end
129
- end
130
- end
131
- end
@@ -1,14 +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
- class NotSupported < Error
9
- def initialize(msg = 'The feature is not supported')
10
- super
11
- end
12
- end
13
- end
14
- end
@@ -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
@@ -1,61 +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
- class StyleRuleApi
8
- def initialize(api, options = {})
9
- @api = api
10
- @options = options
11
- end
12
-
13
- def list(options = {})
14
- DeepL::Requests::StyleRule::List.new(@api, options).request
15
- end
16
-
17
- def create(name, language, options = {})
18
- DeepL::Requests::StyleRule::Create.new(@api, name, language, options).request
19
- end
20
-
21
- def find(style_id, options = {})
22
- DeepL::Requests::StyleRule::Find.new(@api, style_id, options).request
23
- end
24
-
25
- def update_name(style_id, name, options = {})
26
- DeepL::Requests::StyleRule::Update.new(@api, style_id, name, options).request
27
- end
28
-
29
- def destroy(style_id, options = {})
30
- DeepL::Requests::StyleRule::Destroy.new(@api, style_id, options).request
31
- end
32
-
33
- def update_configured_rules(style_id, configured_rules, options = {})
34
- DeepL::Requests::StyleRule::UpdateConfiguredRules.new(@api, style_id, configured_rules,
35
- options).request
36
- end
37
-
38
- def create_custom_instruction(style_id, label, prompt, source_language = nil, options = {})
39
- DeepL::Requests::StyleRule::CreateCustomInstruction.new(@api, style_id, label, prompt,
40
- source_language, options).request
41
- end
42
-
43
- def find_custom_instruction(style_id, instruction_id, options = {})
44
- DeepL::Requests::StyleRule::FindCustomInstruction.new(@api, style_id, instruction_id,
45
- options).request
46
- end
47
-
48
- def update_custom_instruction(style_id, instruction_id, label,
49
- prompt, source_language = nil,
50
- options = {})
51
- DeepL::Requests::StyleRule::UpdateCustomInstruction.new(@api, style_id, instruction_id,
52
- label, prompt, source_language,
53
- options).request
54
- end
55
-
56
- def destroy_custom_instruction(style_id, instruction_id, options = {})
57
- DeepL::Requests::StyleRule::DestroyCustomInstruction.new(@api, style_id, instruction_id,
58
- options).request
59
- end
60
- end
61
- end