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.
- checksums.yaml +4 -4
- data/.rubocop.yml +27 -1
- data/CHANGELOG.md +741 -18
- data/Gemfile +4 -0
- data/README.md +1001 -327
- data/Rakefile +29 -7
- data/VERSION +1 -1
- data/deepl-rb.gemspec +75 -88
- data/lib/deepl/admin_client.rb +208 -0
- data/lib/deepl/api.rb +18 -8
- data/lib/deepl/app_info.rb +19 -0
- data/lib/deepl/client.rb +1284 -0
- data/lib/deepl/configuration.rb +27 -32
- data/lib/deepl/constants/admin_usage_group_by.rb +13 -0
- data/lib/deepl/constants/custom_tag_usage_aggregate_by.rb +13 -0
- data/lib/deepl/constants/document_status_code.rb +17 -0
- data/lib/deepl/constants/language_include.rb +17 -0
- data/lib/deepl/constants/language_resource_name.rb +21 -0
- data/lib/deepl/constants/tag_handling_version.rb +14 -0
- data/lib/deepl/exceptions/authorization_failed.rb +1 -1
- data/lib/deepl/exceptions/bad_request.rb +1 -3
- data/lib/deepl/exceptions/connection_error.rb +40 -0
- data/lib/deepl/exceptions/document_not_ready_error.rb +17 -0
- data/lib/deepl/exceptions/document_translation_error.rb +17 -1
- data/lib/deepl/exceptions/error.rb +13 -1
- data/lib/deepl/exceptions/limit_exceeded.rb +1 -1
- data/lib/deepl/exceptions/not_found.rb +8 -3
- 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 +26 -2
- data/lib/deepl/exceptions/server_error.rb +9 -2
- data/lib/deepl/exceptions/translation_memory_job_error.rb +32 -0
- data/lib/deepl/exceptions/validation_error.rb +15 -0
- data/lib/deepl/requests/admin/base.rb +94 -0
- data/lib/deepl/requests/admin/create_developer_key.rb +38 -0
- data/lib/deepl/requests/admin/custom_tag_usage_analytics.rb +38 -0
- data/lib/deepl/requests/admin/list_developer_keys.rb +28 -0
- data/lib/deepl/requests/admin/update_developer_key.rb +35 -0
- data/lib/deepl/requests/admin/usage_analytics.rb +36 -0
- data/lib/deepl/requests/base.rb +313 -65
- data/lib/deepl/requests/correct.rb +51 -0
- data/lib/deepl/requests/document/download.rb +11 -3
- data/lib/deepl/requests/document/get_status.rb +2 -2
- data/lib/deepl/requests/document/upload.rb +56 -20
- data/lib/deepl/requests/glossary/base.rb +30 -0
- data/lib/deepl/requests/glossary/create.rb +18 -18
- 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 +22 -6
- data/lib/deepl/requests/glossary/list.rb +2 -2
- data/lib/deepl/requests/language_resources.rb +41 -0
- data/lib/deepl/requests/languages.rb +25 -6
- data/lib/deepl/requests/languages_for_resource.rb +56 -0
- data/lib/deepl/requests/multilingual_glossary/create.rb +45 -0
- data/lib/deepl/requests/multilingual_glossary/destroy.rb +36 -0
- data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +55 -0
- data/lib/deepl/requests/multilingual_glossary/entries.rb +68 -0
- data/lib/deepl/requests/multilingual_glossary/find.rb +35 -0
- data/lib/deepl/requests/multilingual_glossary/helpers.rb +71 -0
- data/lib/deepl/requests/multilingual_glossary/list.rb +39 -0
- data/lib/deepl/requests/multilingual_glossary/replace_dictionary.rb +41 -0
- data/lib/deepl/requests/multilingual_glossary/update.rb +40 -0
- data/lib/deepl/requests/rephrase.rb +8 -10
- data/lib/deepl/requests/spoken_terms/create.rb +42 -0
- data/lib/deepl/requests/spoken_terms/destroy.rb +36 -0
- data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +42 -0
- data/lib/deepl/requests/spoken_terms/entries.rb +47 -0
- data/lib/deepl/requests/spoken_terms/find.rb +35 -0
- data/lib/deepl/requests/spoken_terms/helpers.rb +74 -0
- data/lib/deepl/requests/spoken_terms/list.rb +35 -0
- data/lib/deepl/requests/spoken_terms/replace_term_list.rb +41 -0
- data/lib/deepl/requests/spoken_terms/update.rb +40 -0
- data/lib/deepl/requests/style_profile/base.rb +83 -0
- data/lib/deepl/requests/style_profile/create.rb +40 -0
- data/lib/deepl/requests/style_profile/destroy.rb +34 -0
- data/lib/deepl/requests/style_profile/find.rb +33 -0
- data/lib/deepl/requests/style_profile/list.rb +43 -0
- data/lib/deepl/requests/style_profile/update.rb +35 -0
- data/lib/deepl/requests/style_rule/create.rb +24 -0
- data/lib/deepl/requests/style_rule/create_custom_instruction.rb +11 -2
- data/lib/deepl/requests/style_rule/destroy.rb +4 -2
- data/lib/deepl/requests/style_rule/destroy_custom_instruction.rb +5 -3
- data/lib/deepl/requests/style_rule/find.rb +4 -2
- data/lib/deepl/requests/style_rule/find_custom_instruction.rb +5 -3
- data/lib/deepl/requests/style_rule/helpers.rb +44 -0
- data/lib/deepl/requests/style_rule/list.rb +3 -1
- data/lib/deepl/requests/style_rule/update.rb +5 -2
- data/lib/deepl/requests/style_rule/update_configured_rules.rb +4 -2
- data/lib/deepl/requests/style_rule/update_custom_instruction.rb +7 -3
- data/lib/deepl/requests/translate.rb +43 -27
- data/lib/deepl/requests/translation_memory/base.rb +1 -4
- data/lib/deepl/requests/translation_memory/create_export.rb +7 -2
- data/lib/deepl/requests/translation_memory/create_import.rb +11 -1
- data/lib/deepl/requests/translation_memory/destroy.rb +1 -1
- data/lib/deepl/requests/translation_memory/find.rb +1 -1
- data/lib/deepl/requests/translation_memory/find_job.rb +1 -1
- data/lib/deepl/requests/translation_memory/list.rb +4 -3
- data/lib/deepl/requests/translation_memory/segments.rb +5 -4
- data/lib/deepl/requests/translation_memory/storage_base.rb +37 -9
- data/lib/deepl/requests/translation_memory/upload_file.rb +1 -1
- data/lib/deepl/requests/usage.rb +28 -1
- data/lib/deepl/requests/write_improvements.rb +42 -0
- data/lib/deepl/resources/admin_usage_report.rb +73 -0
- data/lib/deepl/resources/custom_tag_usage_report.rb +59 -0
- data/lib/deepl/resources/developer_key.rb +57 -0
- data/lib/deepl/resources/document_handle.rb +8 -34
- data/lib/deepl/resources/document_translation_status.rb +14 -7
- data/lib/deepl/resources/language.rb +5 -3
- data/lib/deepl/resources/language_resource.rb +57 -0
- data/lib/deepl/resources/language_support.rb +56 -0
- data/lib/deepl/resources/multilingual_glossary.rb +112 -0
- data/lib/deepl/resources/spoken_terms.rb +61 -0
- data/lib/deepl/resources/style_profile.rb +44 -0
- data/lib/deepl/resources/style_rule.rb +4 -23
- data/lib/deepl/resources/text.rb +18 -2
- data/lib/deepl/resources/translation_memory.rb +8 -2
- data/lib/deepl/resources/translation_memory_import.rb +1 -1
- data/lib/deepl/resources/translation_memory_job.rb +26 -7
- data/lib/deepl/resources/translation_memory_segments.rb +8 -6
- data/lib/deepl/resources/usage.rb +61 -5
- data/lib/deepl/utils/client_builder.rb +89 -0
- data/lib/deepl/utils/document_poller.rb +70 -0
- data/lib/deepl/utils/exception_builder.rb +3 -2
- data/lib/deepl/utils/glossary_entries.rb +30 -0
- data/lib/deepl/utils/http_client_builder.rb +116 -0
- data/lib/deepl/utils/number_parser.rb +34 -0
- data/lib/deepl/utils/output_path.rb +25 -0
- data/lib/deepl/utils/term_validator.rb +33 -0
- data/lib/deepl/utils/time_parser.rb +14 -0
- data/lib/deepl/utils/translation_memory_operations.rb +230 -0
- data/lib/deepl.rb +68 -108
- data/lib/http_client_options.rb +21 -1
- data/lib/version.rb +1 -1
- data/upgrading_to_v4.md +374 -0
- metadata +84 -85
- data/.circleci/config.yml +0 -27
- data/.github/workflows/add_issues_to_kanban.yml +0 -16
- data/.gitlab-ci.yml +0 -179
- data/lib/deepl/document_api.rb +0 -131
- data/lib/deepl/exceptions/not_supported.rb +0 -14
- data/lib/deepl/glossary_api.rb +0 -38
- data/lib/deepl/style_rule_api.rb +0 -61
- data/lib/deepl/translation_memory_api.rb +0 -309
- data/license_checker.sh +0 -8
- data/spec/api/api_spec.rb +0 -20
- data/spec/api/configuration_spec.rb +0 -122
- data/spec/api/deepl_spec.rb +0 -262
- data/spec/constants/constants_spec.rb +0 -158
- data/spec/integration_tests/document_api_spec.rb +0 -211
- data/spec/integration_tests/document_error_paths_spec.rb +0 -33
- data/spec/integration_tests/glossary_api_spec.rb +0 -114
- data/spec/integration_tests/glossary_error_paths_spec.rb +0 -107
- data/spec/integration_tests/integration_test_utils.rb +0 -178
- data/spec/integration_tests/languages_api_spec.rb +0 -54
- data/spec/integration_tests/languages_error_paths_spec.rb +0 -25
- data/spec/integration_tests/rephrase_api_spec.rb +0 -90
- data/spec/integration_tests/rephrase_error_paths_spec.rb +0 -53
- data/spec/integration_tests/smoke_test_spec.rb +0 -24
- data/spec/integration_tests/style_rule_api_spec.rb +0 -117
- data/spec/integration_tests/style_rule_error_paths_spec.rb +0 -45
- data/spec/integration_tests/translate_api_spec.rb +0 -117
- data/spec/integration_tests/translate_error_paths_spec.rb +0 -48
- data/spec/integration_tests/translation_memory_api_spec.rb +0 -244
- data/spec/integration_tests/translation_memory_error_paths_spec.rb +0 -87
- data/spec/integration_tests/usage_api_spec.rb +0 -29
- data/spec/integration_tests/usage_error_paths_spec.rb +0 -18
- data/spec/requests/document/upload_spec.rb +0 -130
- data/spec/requests/extra_body_parameters_types_spec.rb +0 -82
- data/spec/requests/glossary/create_spec.rb +0 -44
- data/spec/requests/glossary/destroy_spec.rb +0 -27
- data/spec/requests/glossary/entries_spec.rb +0 -27
- data/spec/requests/glossary/find_spec.rb +0 -28
- data/spec/requests/glossary/language_pairs_spec.rb +0 -27
- data/spec/requests/glossary/list_spec.rb +0 -27
- data/spec/requests/languages_spec.rb +0 -27
- data/spec/requests/rephrase_spec.rb +0 -46
- data/spec/requests/style_rule/create_custom_instruction_spec.rb +0 -30
- data/spec/requests/style_rule/create_spec.rb +0 -29
- data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +0 -28
- data/spec/requests/style_rule/destroy_spec.rb +0 -27
- data/spec/requests/style_rule/find_custom_instruction_spec.rb +0 -29
- data/spec/requests/style_rule/find_spec.rb +0 -28
- data/spec/requests/style_rule/list_spec.rb +0 -27
- data/spec/requests/style_rule/update_configured_rules_spec.rb +0 -31
- data/spec/requests/style_rule/update_custom_instruction_spec.rb +0 -32
- data/spec/requests/style_rule/update_spec.rb +0 -29
- data/spec/requests/translate_spec.rb +0 -338
- data/spec/requests/translation_memory/create_export_spec.rb +0 -37
- data/spec/requests/translation_memory/create_import_spec.rb +0 -61
- data/spec/requests/translation_memory/destroy_spec.rb +0 -36
- data/spec/requests/translation_memory/download_export_spec.rb +0 -54
- data/spec/requests/translation_memory/find_job_spec.rb +0 -37
- data/spec/requests/translation_memory/find_spec.rb +0 -36
- data/spec/requests/translation_memory/list_spec.rb +0 -27
- data/spec/requests/translation_memory/segments_spec.rb +0 -58
- data/spec/requests/translation_memory/upload_file_spec.rb +0 -55
- data/spec/requests/usage_spec.rb +0 -27
- data/spec/resources/custom_instruction_spec.rb +0 -32
- data/spec/resources/glossary_spec.rb +0 -38
- data/spec/resources/language_pair_spec.rb +0 -23
- data/spec/resources/language_spec.rb +0 -45
- data/spec/resources/style_rule_spec.rb +0 -68
- data/spec/resources/text_spec.rb +0 -23
- data/spec/resources/translation_memory_export_spec.rb +0 -38
- data/spec/resources/translation_memory_import_spec.rb +0 -30
- data/spec/resources/translation_memory_job_spec.rb +0 -109
- data/spec/resources/translation_memory_segments_spec.rb +0 -78
- data/spec/resources/translation_memory_spec.rb +0 -52
- data/spec/resources/usage_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -62
- data/spec/support/live_mock_server.rb +0 -12
- data/spec/support/managed_glossary.rb +0 -65
- data/spec/support/managed_style_rule.rb +0 -17
- data/spec/support/managed_translation_memory.rb +0 -55
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
module Resources
|
|
8
|
+
##
|
|
9
|
+
# Usage limits of a developer key. A +nil+ limit means unlimited.
|
|
10
|
+
class DeveloperKeyUsageLimits
|
|
11
|
+
attr_reader :characters, :speech_to_text_milliseconds, :speech_to_speech_milliseconds
|
|
12
|
+
|
|
13
|
+
def initialize(usage_limits)
|
|
14
|
+
usage_limits = {} unless usage_limits.is_a?(Hash)
|
|
15
|
+
@characters = Utils::NumberParser.optional_count(usage_limits['characters'])
|
|
16
|
+
@speech_to_text_milliseconds =
|
|
17
|
+
Utils::NumberParser.optional_count(usage_limits['speech_to_text_milliseconds'])
|
|
18
|
+
@speech_to_speech_milliseconds =
|
|
19
|
+
Utils::NumberParser.optional_count(usage_limits['speech_to_speech_milliseconds'])
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# A developer key. +label+ and +usage_limits+ are +nil+ when the response does not contain
|
|
25
|
+
# them.
|
|
26
|
+
class DeveloperKey < Base
|
|
27
|
+
attr_reader :key_id, :label, :creation_time, :deactivated_time, :is_deactivated,
|
|
28
|
+
:usage_limits
|
|
29
|
+
|
|
30
|
+
def initialize(developer_key, *args)
|
|
31
|
+
super(*args)
|
|
32
|
+
developer_key = {} unless developer_key.is_a?(Hash)
|
|
33
|
+
@key_id = developer_key['key_id'].is_a?(String) ? developer_key['key_id'] : ''
|
|
34
|
+
@label = developer_key['label'].is_a?(String) ? developer_key['label'] : nil
|
|
35
|
+
@creation_time = Utils::TimeParser.parse_optional_utc_time(developer_key['creation_time'])
|
|
36
|
+
@deactivated_time =
|
|
37
|
+
Utils::TimeParser.parse_optional_utc_time(developer_key['deactivated_time'])
|
|
38
|
+
@is_deactivated = developer_key['is_deactivated'] == true
|
|
39
|
+
@usage_limits = parse_usage_limits(developer_key['usage_limits'])
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def deactivated?
|
|
43
|
+
is_deactivated
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def to_s
|
|
47
|
+
label.nil? ? key_id : "#{label} (#{key_id})"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def parse_usage_limits(usage_limits)
|
|
53
|
+
usage_limits.is_a?(Hash) ? DeveloperKeyUsageLimits.new(usage_limits) : nil
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -8,49 +8,23 @@ module DeepL
|
|
|
8
8
|
class DocumentHandle < Base
|
|
9
9
|
attr_reader :document_id, :document_key
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
# The +api:+ keyword is kept for compatibility and not used.
|
|
12
|
+
# A handle for a stored ID and key needs only those two: +DocumentHandle.new(id, key)+.
|
|
13
|
+
def initialize(document_id, document_key, request = nil, response = nil, api: nil)
|
|
14
|
+
super(request, response)
|
|
13
15
|
|
|
14
16
|
@document_id = document_id
|
|
15
17
|
@document_key = document_key
|
|
18
|
+
@api = api
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
def to_s
|
|
19
22
|
"DocumentHandle: ID: #{document_id} - Key: #{document_key}"
|
|
20
23
|
end
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
#
|
|
26
|
-
# @return [DeepL::Resources::DocumentTranslationStatus] Final status of the document
|
|
27
|
-
# translation.
|
|
28
|
-
|
|
29
|
-
def wait_until_document_translation_finished
|
|
30
|
-
doc_status = nil
|
|
31
|
-
max_tries = max_doc_status_queries
|
|
32
|
-
num_tries = 0
|
|
33
|
-
loop do
|
|
34
|
-
num_tries += 1
|
|
35
|
-
sleep(calculate_waiting_time(doc_status)) unless doc_status.nil?
|
|
36
|
-
doc_status = DeepL.document.get_status(self)
|
|
37
|
-
break if doc_status.finished? || num_tries > max_tries
|
|
38
|
-
end
|
|
39
|
-
doc_status
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
def calculate_waiting_time(_resp)
|
|
45
|
-
# ignore _resp.seconds_remaining for now, while it is unreliable
|
|
46
|
-
5
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def max_doc_status_queries
|
|
50
|
-
configured_value = DeepL.configuration.max_doc_status_queries
|
|
51
|
-
return configured_value unless configured_value.nil?
|
|
52
|
-
|
|
53
|
-
10
|
|
25
|
+
# Leaves out the connection, which holds the auth key.
|
|
26
|
+
def inspect
|
|
27
|
+
"#<#{self.class.name} document_id=#{document_id.inspect}>"
|
|
54
28
|
end
|
|
55
29
|
end
|
|
56
30
|
end
|
|
@@ -24,12 +24,11 @@ module DeepL
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
##
|
|
27
|
-
# Checks if the translation
|
|
27
|
+
# Checks if the translation is done, so the document can be downloaded.
|
|
28
28
|
#
|
|
29
|
-
# @return [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
status == 'done'
|
|
29
|
+
# @return [Boolean] +true+ if the status is +done+.
|
|
30
|
+
def done?
|
|
31
|
+
status == Constants::DocumentStatusCode::DONE
|
|
33
32
|
end
|
|
34
33
|
|
|
35
34
|
##
|
|
@@ -38,7 +37,15 @@ module DeepL
|
|
|
38
37
|
# @return [true] if so
|
|
39
38
|
|
|
40
39
|
def error?
|
|
41
|
-
status ==
|
|
40
|
+
status == Constants::DocumentStatusCode::ERROR
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
##
|
|
44
|
+
# Checks that the translation has not failed. Also true while it is queued or translating.
|
|
45
|
+
#
|
|
46
|
+
# @return [Boolean] +true+ unless the status is +error+.
|
|
47
|
+
def ok?
|
|
48
|
+
!error?
|
|
42
49
|
end
|
|
43
50
|
|
|
44
51
|
##
|
|
@@ -47,7 +54,7 @@ module DeepL
|
|
|
47
54
|
#
|
|
48
55
|
# @return [true] if so
|
|
49
56
|
def finished?
|
|
50
|
-
|
|
57
|
+
done? || error?
|
|
51
58
|
end
|
|
52
59
|
end
|
|
53
60
|
end
|
|
@@ -20,10 +20,12 @@ module DeepL
|
|
|
20
20
|
"#{code} - #{name}"
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
# Whether the target language supports the +formality+ option.
|
|
24
|
+
#
|
|
25
|
+
# @return [Boolean, nil] +true+ or +false+ for a target language, +nil+ for a source
|
|
26
|
+
# language.
|
|
23
27
|
def supports_formality?
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
raise Exceptions::NotSupported, 'Support formality is only available on target languages'
|
|
28
|
+
@supports_formality
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
end
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
module DeepL
|
|
7
|
+
module Resources
|
|
8
|
+
# A feature supported by a DeepL API resource, as returned by `DeepL::Client#get_language_resources`.
|
|
9
|
+
class ResourceFeature
|
|
10
|
+
attr_reader :name
|
|
11
|
+
|
|
12
|
+
def initialize(feature)
|
|
13
|
+
@name = feature['name']
|
|
14
|
+
@needs_source_support = feature['needs_source_support'] ? true : false
|
|
15
|
+
@needs_target_support = feature['needs_target_support'] ? true : false
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_s
|
|
19
|
+
name
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# True if the source language must support this feature for it to be available.
|
|
23
|
+
def needs_source_support?
|
|
24
|
+
@needs_source_support
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# True if the target language must support this feature for it to be available.
|
|
28
|
+
def needs_target_support?
|
|
29
|
+
@needs_target_support
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# A DeepL API resource and the features it supports, as returned by `DeepL::Client#get_language_resources`.
|
|
34
|
+
class LanguageResource < Base
|
|
35
|
+
attr_reader :name, :features
|
|
36
|
+
|
|
37
|
+
def initialize(resource, *args)
|
|
38
|
+
super(*args)
|
|
39
|
+
|
|
40
|
+
@name = resource['name']
|
|
41
|
+
@features = (resource['features'] || []).to_h do |feature|
|
|
42
|
+
resource_feature = ResourceFeature.new(feature)
|
|
43
|
+
[resource_feature.name, resource_feature]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_s
|
|
48
|
+
name
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Returns true if this resource exposes the given feature (e.g. 'glossary').
|
|
52
|
+
def supports?(feature)
|
|
53
|
+
features.key?(feature.to_s)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
module DeepL
|
|
7
|
+
module Resources
|
|
8
|
+
# Support level of a single feature of a language for a resource.
|
|
9
|
+
class LanguageFeature
|
|
10
|
+
attr_reader :status
|
|
11
|
+
|
|
12
|
+
def initialize(status)
|
|
13
|
+
@status = status
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_s
|
|
17
|
+
status.to_s
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# A language supported by a DeepL API resource, as returned by `DeepL::Client#get_languages_for_resource`.
|
|
22
|
+
class LanguageSupport < Base
|
|
23
|
+
attr_reader :code, :name, :status, :features
|
|
24
|
+
|
|
25
|
+
def initialize(language, *args)
|
|
26
|
+
super(*args)
|
|
27
|
+
|
|
28
|
+
@code = language['lang']
|
|
29
|
+
@name = language['name']
|
|
30
|
+
@status = language['status']
|
|
31
|
+
@usable_as_source = language['usable_as_source'] ? true : false
|
|
32
|
+
@usable_as_target = language['usable_as_target'] ? true : false
|
|
33
|
+
@features = (language['features'] || {}).to_h.transform_values do |feature|
|
|
34
|
+
LanguageFeature.new(feature.to_h['status'])
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def to_s
|
|
39
|
+
"#{name} (#{code})"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def usable_as_source?
|
|
43
|
+
@usable_as_source
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def usable_as_target?
|
|
47
|
+
@usable_as_target
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Returns true if this language supports the given feature (e.g. 'formality').
|
|
51
|
+
def supports?(feature)
|
|
52
|
+
features.key?(feature.to_s)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
module Resources
|
|
8
|
+
class MultilingualGlossaryDictionary < Base
|
|
9
|
+
attr_reader :source_lang, :target_lang, :entry_count
|
|
10
|
+
|
|
11
|
+
def initialize(dictionary, *args)
|
|
12
|
+
super(*args)
|
|
13
|
+
|
|
14
|
+
@source_lang = dictionary['source_lang']
|
|
15
|
+
@target_lang = dictionary['target_lang']
|
|
16
|
+
@entry_count = dictionary['entry_count']
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
"#{source_lang} -> #{target_lang} (#{entry_count})"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# The entries of one dictionary. Used as input for +create_multilingual_glossary+,
|
|
25
|
+
# +update_multilingual_glossary+, +update_multilingual_glossary_dictionary+ and
|
|
26
|
+
# +replace_multilingual_glossary_dictionary+, and returned by
|
|
27
|
+
# +get_multilingual_glossary_dictionary_entries+.
|
|
28
|
+
class MultilingualGlossaryDictionaryEntries < Base
|
|
29
|
+
# @return [Hash{String => String}] The target term of each source term.
|
|
30
|
+
attr_reader :entries
|
|
31
|
+
attr_reader :source_lang, :target_lang
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# @param [String] source_lang Source language code, for example +'en'+.
|
|
35
|
+
# @param [String] target_lang Target language code, for example +'de'+.
|
|
36
|
+
# @param [Hash{String => String}, Array<Array(String, String)>, String] entries The target
|
|
37
|
+
# term of each source term, as a hash, source/target pairs or a TSV string; terms are
|
|
38
|
+
# stripped and checked when sent.
|
|
39
|
+
# @raise [DeepL::Exceptions::ValidationError] (an ArgumentError) If a pair or TSV line is not
|
|
40
|
+
# exactly two terms, or a source term appears twice.
|
|
41
|
+
def initialize(source_lang, target_lang, entries, request = nil, response = nil)
|
|
42
|
+
super(request, response)
|
|
43
|
+
|
|
44
|
+
@source_lang = source_lang
|
|
45
|
+
@target_lang = target_lang
|
|
46
|
+
pairs = entries.is_a?(String) ? self.class.tsv_to_pairs(entries) : entries.to_a
|
|
47
|
+
@entries = self.class.check_pairs!(pairs).to_h
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# @api private
|
|
51
|
+
# Builds the entries from a dictionary of the API, whose entries are a TSV string.
|
|
52
|
+
def self.from_response(dictionary, request, response)
|
|
53
|
+
entries = (dictionary['entries'] || '').split(/\r?\n/).reject(&:empty?).to_h do |line|
|
|
54
|
+
source, target = line.split("\t", 2)
|
|
55
|
+
[source, target]
|
|
56
|
+
end
|
|
57
|
+
new(dictionary['source_lang'], dictionary['target_lang'], entries, request, response)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# @api private
|
|
61
|
+
# Raises ValidationError unless each pair is two terms and no source term, stripped as
|
|
62
|
+
# the term check strips it, appears twice. Returns +pairs+.
|
|
63
|
+
def self.check_pairs!(pairs)
|
|
64
|
+
seen = {}
|
|
65
|
+
pairs.each do |pair|
|
|
66
|
+
unless pair.size == 2
|
|
67
|
+
raise Exceptions::ValidationError, "Entry #{pair.inspect} must be two terms"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
source = pair.first.strip
|
|
71
|
+
next seen[source] = true unless seen[source]
|
|
72
|
+
|
|
73
|
+
raise Exceptions::ValidationError, "Duplicate source term #{source.inspect}"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# @api private
|
|
78
|
+
# One source/target pair per non-blank line, separated by a single tab.
|
|
79
|
+
def self.tsv_to_pairs(tsv)
|
|
80
|
+
tsv.split(/\r?\n/).reject { |line| line.strip.empty? }.map do |line|
|
|
81
|
+
pair = line.split("\t", -1)
|
|
82
|
+
unless pair.size == 2
|
|
83
|
+
raise Exceptions::ValidationError,
|
|
84
|
+
"TSV entry #{line.inspect} must be a source and a target term separated by " \
|
|
85
|
+
'one tab'
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
pair
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
class MultilingualGlossary < Base
|
|
94
|
+
attr_reader :id, :name, :creation_time, :dictionaries
|
|
95
|
+
|
|
96
|
+
def initialize(glossary, *args)
|
|
97
|
+
super(*args)
|
|
98
|
+
|
|
99
|
+
@id = glossary['glossary_id']
|
|
100
|
+
@name = glossary['name']
|
|
101
|
+
@creation_time = Utils::TimeParser.parse_optional_utc_time(glossary['creation_time'])
|
|
102
|
+
@dictionaries = (glossary['dictionaries'] || []).map do |dictionary|
|
|
103
|
+
MultilingualGlossaryDictionary.new(dictionary, *args)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def to_s
|
|
108
|
+
"#{id} - #{name}"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
module Resources
|
|
8
|
+
# The term count of one language in a spoken terms collection.
|
|
9
|
+
class SpokenTermsList < Base
|
|
10
|
+
attr_reader :lang, :entry_count
|
|
11
|
+
|
|
12
|
+
def initialize(term_list, *args)
|
|
13
|
+
super(*args)
|
|
14
|
+
|
|
15
|
+
@lang = term_list['lang']
|
|
16
|
+
@entry_count = term_list['entry_count']
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
"#{lang} (#{entry_count})"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# The terms of one language. Used as input for +create_spoken_terms+,
|
|
25
|
+
# +update_spoken_terms+ and +replace_spoken_terms_list+, and returned by
|
|
26
|
+
# +get_spoken_terms_entries+.
|
|
27
|
+
class SpokenTermsEntries < Base
|
|
28
|
+
attr_reader :lang, :entries
|
|
29
|
+
|
|
30
|
+
##
|
|
31
|
+
# @param [String] lang Language code, for example +'en'+.
|
|
32
|
+
# @param [Array<String>] entries The terms, one per element.
|
|
33
|
+
def initialize(lang, entries, request = nil, response = nil)
|
|
34
|
+
super(request, response)
|
|
35
|
+
|
|
36
|
+
@lang = lang
|
|
37
|
+
@entries = entries
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# A spoken terms collection.
|
|
42
|
+
class SpokenTerms < Base
|
|
43
|
+
attr_reader :spoken_terms_id, :name, :creation_time, :term_lists
|
|
44
|
+
|
|
45
|
+
def initialize(spoken_terms, *args)
|
|
46
|
+
super(*args)
|
|
47
|
+
|
|
48
|
+
@spoken_terms_id = spoken_terms['spoken_terms_id']
|
|
49
|
+
@name = spoken_terms['name']
|
|
50
|
+
@creation_time = Utils::TimeParser.parse_optional_utc_time(spoken_terms['creation_time'])
|
|
51
|
+
@term_lists = (spoken_terms['term_lists'] || []).map do |term_list|
|
|
52
|
+
SpokenTermsList.new(term_list, *args)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def to_s
|
|
57
|
+
"#{spoken_terms_id} - #{name}"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
module Resources
|
|
8
|
+
# A style profile: a named set of glossaries, style rule lists and translation memories.
|
|
9
|
+
class StyleProfile < Base
|
|
10
|
+
attr_reader :style_profile_id, :name, :description, :industry, :glossary_ids, :style_rule_ids,
|
|
11
|
+
:translation_memory_ids, :glossary_priority_order_enabled, :creation_time,
|
|
12
|
+
:updated_time
|
|
13
|
+
|
|
14
|
+
def initialize(profile, *args) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
|
15
|
+
super(*args)
|
|
16
|
+
|
|
17
|
+
@style_profile_id = profile['style_profile_id']
|
|
18
|
+
@name = profile['name']
|
|
19
|
+
@description = optional_string(profile['description'])
|
|
20
|
+
@industry = optional_string(profile['industry'])
|
|
21
|
+
@glossary_ids = id_list(profile['glossary_ids'])
|
|
22
|
+
@style_rule_ids = id_list(profile['style_rule_ids'])
|
|
23
|
+
@translation_memory_ids = id_list(profile['translation_memory_ids'])
|
|
24
|
+
@glossary_priority_order_enabled = profile['glossary_priority_order_enabled'] == true
|
|
25
|
+
@creation_time = Utils::TimeParser.parse_optional_utc_time(profile['creation_time'])
|
|
26
|
+
@updated_time = Utils::TimeParser.parse_optional_utc_time(profile['updated_time'])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def to_s
|
|
30
|
+
"#{style_profile_id} - #{name}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def optional_string(value)
|
|
36
|
+
value if value.is_a?(String)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def id_list(value)
|
|
40
|
+
value.is_a?(Array) ? value.grep(String) : []
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -7,27 +7,6 @@ require 'time'
|
|
|
7
7
|
|
|
8
8
|
module DeepL
|
|
9
9
|
module Resources
|
|
10
|
-
class ConfiguredRules
|
|
11
|
-
attr_reader :dates_and_times, :formatting, :numbers, :punctuation,
|
|
12
|
-
:spelling_and_grammar, :style_and_tone, :vocabulary
|
|
13
|
-
|
|
14
|
-
def initialize(configured_rules_data)
|
|
15
|
-
@dates_and_times = extract_rule(configured_rules_data, 'dates_and_times')
|
|
16
|
-
@formatting = extract_rule(configured_rules_data, 'formatting')
|
|
17
|
-
@numbers = extract_rule(configured_rules_data, 'numbers')
|
|
18
|
-
@punctuation = extract_rule(configured_rules_data, 'punctuation')
|
|
19
|
-
@spelling_and_grammar = extract_rule(configured_rules_data, 'spelling_and_grammar')
|
|
20
|
-
@style_and_tone = extract_rule(configured_rules_data, 'style_and_tone')
|
|
21
|
-
@vocabulary = extract_rule(configured_rules_data, 'vocabulary')
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
def extract_rule(data, key)
|
|
27
|
-
data[key] || {}
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
10
|
class CustomInstruction
|
|
32
11
|
attr_reader :id, :label, :prompt, :source_language
|
|
33
12
|
|
|
@@ -62,8 +41,7 @@ module DeepL
|
|
|
62
41
|
end
|
|
63
42
|
|
|
64
43
|
def extract_configured_rules(style_rule)
|
|
65
|
-
|
|
66
|
-
@configured_rules = configured_rules_data ? ConfiguredRules.new(configured_rules_data) : nil
|
|
44
|
+
@configured_rules = style_rule['configured_rules']
|
|
67
45
|
end
|
|
68
46
|
|
|
69
47
|
def extract_custom_instructions(style_rule)
|
|
@@ -80,6 +58,9 @@ module DeepL
|
|
|
80
58
|
return nil unless time_string
|
|
81
59
|
|
|
82
60
|
Time.parse(time_string)
|
|
61
|
+
rescue ArgumentError, TypeError
|
|
62
|
+
raise Exceptions::Error,
|
|
63
|
+
"Unexpected response from the DeepL API: invalid time #{time_string.inspect}"
|
|
83
64
|
end
|
|
84
65
|
end
|
|
85
66
|
end
|
data/lib/deepl/resources/text.rb
CHANGED
|
@@ -6,14 +6,30 @@
|
|
|
6
6
|
module DeepL
|
|
7
7
|
module Resources
|
|
8
8
|
class Text < Base
|
|
9
|
+
# @return [Integer, nil] Number of characters billed for the text, +nil+ if the response
|
|
10
|
+
# does not contain it.
|
|
11
|
+
attr_reader :billed_characters
|
|
12
|
+
# @return [String, nil] Tag handling algorithm version used (see
|
|
13
|
+
# +DeepL::Constants::TagHandlingVersion+), +nil+ if the response does not contain it.
|
|
14
|
+
attr_reader :tag_handling_version
|
|
15
|
+
# @return [String, nil] Target language of a rephrase or correct result, +nil+ for text
|
|
16
|
+
# translation results and if the response does not contain it.
|
|
17
|
+
attr_reader :target_language
|
|
9
18
|
attr_reader :text, :detected_source_language, :model_type_used
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
# Positional, not keyword, parameters: Ruby 2.7 would read the response (it has +to_hash+)
|
|
21
|
+
# as keywords.
|
|
22
|
+
def initialize(text, detected_source_language, model_type_used, request = nil, # rubocop:disable Metrics/ParameterLists
|
|
23
|
+
response = nil, billed_characters = nil, tag_handling_version = nil,
|
|
24
|
+
target_language = nil)
|
|
25
|
+
super(request, response)
|
|
13
26
|
|
|
14
27
|
@text = text
|
|
15
28
|
@detected_source_language = detected_source_language
|
|
16
29
|
@model_type_used = model_type_used
|
|
30
|
+
@billed_characters = billed_characters
|
|
31
|
+
@tag_handling_version = tag_handling_version
|
|
32
|
+
@target_language = target_language
|
|
17
33
|
end
|
|
18
34
|
|
|
19
35
|
def to_s
|
|
@@ -16,13 +16,19 @@ module DeepL
|
|
|
16
16
|
@source_language = translation_memory['source_language']
|
|
17
17
|
@target_languages = translation_memory['target_languages'] || []
|
|
18
18
|
@segment_count = translation_memory['segment_count'] || 0
|
|
19
|
-
@creation_time =
|
|
20
|
-
@updated_time =
|
|
19
|
+
@creation_time = parse_time(translation_memory['creation_time'])
|
|
20
|
+
@updated_time = parse_time(translation_memory['updated_time'])
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def to_s
|
|
24
24
|
"#{translation_memory_id} - #{name}"
|
|
25
25
|
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def parse_time(value)
|
|
30
|
+
Utils::TimeParser.parse_optional_utc_time(value)
|
|
31
|
+
end
|
|
26
32
|
end
|
|
27
33
|
end
|
|
28
34
|
end
|
|
@@ -16,7 +16,7 @@ module DeepL
|
|
|
16
16
|
super(*args)
|
|
17
17
|
@job_id = translation_memory_import['job_id']
|
|
18
18
|
@upload_url = translation_memory_import['upload_url']
|
|
19
|
-
@expires_at = Utils::TimeParser.
|
|
19
|
+
@expires_at = Utils::TimeParser.parse_optional_utc_time(
|
|
20
20
|
translation_memory_import['expires_at']
|
|
21
21
|
)
|
|
22
22
|
end
|