deepl-rb 3.8.0 → 3.10.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/.gitlab-ci.yml +71 -53
- data/.rubocop.yml +26 -0
- data/CHANGELOG.md +450 -17
- data/Gemfile +4 -0
- data/README.md +1119 -152
- data/Rakefile +18 -5
- data/VERSION +1 -1
- data/deepl-rb.gemspec +31 -3
- data/lib/deepl/admin_client.rb +183 -0
- data/lib/deepl/api.rb +30 -6
- data/lib/deepl/app_info.rb +20 -0
- data/lib/deepl/client.rb +969 -0
- data/lib/deepl/configuration.rb +56 -10
- 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/deprecation.rb +42 -0
- data/lib/deepl/document_api.rb +45 -16
- data/lib/deepl/exceptions/bad_request.rb +1 -3
- data/lib/deepl/exceptions/connection_error.rb +37 -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/not_found.rb +8 -3
- data/lib/deepl/exceptions/not_supported.rb +6 -0
- data/lib/deepl/exceptions/request_error.rb +19 -2
- data/lib/deepl/exceptions/server_error.rb +7 -1
- data/lib/deepl/exceptions/validation_error.rb +14 -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 +265 -43
- data/lib/deepl/requests/correct.rb +57 -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 +92 -10
- data/lib/deepl/requests/glossary/create.rb +6 -2
- data/lib/deepl/requests/glossary/language_pairs.rb +20 -4
- data/lib/deepl/requests/language_resources.rb +41 -0
- data/lib/deepl/requests/languages.rb +28 -4
- data/lib/deepl/requests/languages_for_resource.rb +54 -0
- data/lib/deepl/requests/multilingual_glossary/create.rb +37 -0
- data/lib/deepl/requests/multilingual_glossary/destroy.rb +36 -0
- data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +51 -0
- data/lib/deepl/requests/multilingual_glossary/entries.rb +66 -0
- data/lib/deepl/requests/multilingual_glossary/find.rb +35 -0
- data/lib/deepl/requests/multilingual_glossary/helpers.rb +63 -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 +5 -9
- data/lib/deepl/requests/spoken_terms/create.rb +37 -0
- data/lib/deepl/requests/spoken_terms/destroy.rb +36 -0
- data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +41 -0
- data/lib/deepl/requests/spoken_terms/entries.rb +46 -0
- data/lib/deepl/requests/spoken_terms/find.rb +35 -0
- data/lib/deepl/requests/spoken_terms/helpers.rb +67 -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 +35 -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 +1 -1
- data/lib/deepl/requests/style_rule/create_custom_instruction.rb +4 -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 +35 -0
- data/lib/deepl/requests/style_rule/list.rb +1 -1
- data/lib/deepl/requests/style_rule/update.rb +4 -2
- data/lib/deepl/requests/style_rule/update_configured_rules.rb +4 -2
- data/lib/deepl/requests/style_rule/update_custom_instruction.rb +5 -3
- data/lib/deepl/requests/translate.rb +55 -20
- data/lib/deepl/requests/translation_memory/base.rb +44 -0
- data/lib/deepl/requests/translation_memory/create_export.rb +41 -0
- data/lib/deepl/requests/translation_memory/create_import.rb +53 -0
- data/lib/deepl/requests/translation_memory/destroy.rb +37 -0
- data/lib/deepl/requests/translation_memory/download_export.rb +39 -0
- data/lib/deepl/requests/translation_memory/find.rb +38 -0
- data/lib/deepl/requests/translation_memory/find_job.rb +38 -0
- data/lib/deepl/requests/translation_memory/list.rb +6 -18
- data/lib/deepl/requests/translation_memory/segments.rb +47 -0
- data/lib/deepl/requests/translation_memory/storage_base.rb +79 -0
- data/lib/deepl/requests/translation_memory/upload_file.rb +47 -0
- data/lib/deepl/requests/usage.rb +28 -1
- data/lib/deepl/requests/write_improvements.rb +35 -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 +24 -25
- data/lib/deepl/resources/document_translation_status.rb +23 -4
- data/lib/deepl/resources/language.rb +10 -2
- 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 +3 -0
- data/lib/deepl/resources/text.rb +18 -2
- data/lib/deepl/resources/translation_memory.rb +10 -1
- data/lib/deepl/resources/translation_memory_export.rb +37 -0
- data/lib/deepl/resources/translation_memory_import.rb +29 -0
- data/lib/deepl/resources/translation_memory_job.rb +162 -0
- data/lib/deepl/resources/translation_memory_segments.rb +80 -0
- data/lib/deepl/resources/usage.rb +93 -4
- data/lib/deepl/style_rule_api.rb +11 -0
- data/lib/deepl/translation_memory_api.rb +373 -1
- data/lib/deepl/utils/client_builder.rb +54 -0
- data/lib/deepl/utils/document_poller.rb +70 -0
- data/lib/deepl/utils/exception_builder.rb +3 -2
- data/lib/deepl/utils/http_client_builder.rb +79 -0
- data/lib/deepl/utils/number_parser.rb +34 -0
- data/lib/deepl/utils/term_validator.rb +33 -0
- data/lib/deepl/utils/time_parser.rb +40 -0
- data/lib/deepl.rb +190 -34
- data/lib/http_client_options.rb +21 -1
- data/lib/version.rb +1 -1
- data/spec/fixtures.rb +33 -0
- data/spec/offline/admin_client_spec.rb +551 -0
- data/spec/offline/client_spec.rb +273 -0
- data/spec/{api → offline}/configuration_spec.rb +45 -3
- data/spec/{constants → offline}/constants_spec.rb +23 -1
- data/spec/offline/correct_text_spec.rb +50 -0
- data/spec/offline/deprecation_spec.rb +32 -0
- data/spec/offline/errors_spec.rb +92 -0
- data/spec/offline/glossaries_spec.rb +98 -0
- data/spec/offline/http_client_spec.rb +319 -0
- data/spec/offline/languages_spec.rb +155 -0
- data/spec/offline/module_methods_spec.rb +13 -0
- data/spec/offline/multilingual_glossaries_spec.rb +358 -0
- data/spec/offline/offline_helper.rb +71 -0
- data/spec/offline/rephrase_text_spec.rb +73 -0
- data/spec/offline/spoken_terms_spec.rb +215 -0
- data/spec/offline/style_profiles_spec.rb +266 -0
- data/spec/offline/style_rules_spec.rb +318 -0
- data/spec/offline/translate_document_spec.rb +606 -0
- data/spec/offline/translate_text_spec.rb +286 -0
- data/spec/offline/translation_memories_client_spec.rb +256 -0
- data/spec/offline/translation_memories_spec.rb +463 -0
- data/spec/offline/usage_spec.rb +151 -0
- data/spec/real_api/admin_client_spec.rb +77 -0
- data/spec/real_api/correct_text_spec.rb +20 -0
- data/spec/real_api/glossaries_spec.rb +28 -0
- data/spec/real_api/languages_spec.rb +27 -0
- data/spec/real_api/multilingual_glossaries_spec.rb +53 -0
- data/spec/real_api/proxy_spec.rb +41 -0
- data/spec/real_api/real_api_helper.rb +65 -0
- data/spec/real_api/rephrase_text_spec.rb +16 -0
- data/spec/real_api/spoken_terms_spec.rb +56 -0
- data/spec/real_api/style_profiles_spec.rb +46 -0
- data/spec/real_api/style_rules_spec.rb +46 -0
- data/spec/real_api/translate_document_spec.rb +18 -0
- data/spec/real_api/translate_text_spec.rb +16 -0
- data/spec/real_api/translation_memories_spec.rb +56 -0
- data/spec/real_api/usage_spec.rb +20 -0
- data/spec/spec_helper.rb +1 -50
- metadata +134 -63
- data/.circleci/config.yml +0 -27
- data/.github/workflows/add_issues_to_kanban.yml +0 -16
- data/spec/api/api_spec.rb +0 -20
- data/spec/api/deepl_spec.rb +0 -262
- data/spec/integration_tests/document_api_spec.rb +0 -164
- 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 -170
- 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 -98
- data/spec/integration_tests/translate_error_paths_spec.rb +0 -48
- data/spec/integration_tests/translation_memory_api_spec.rb +0 -54
- data/spec/integration_tests/translation_memory_error_paths_spec.rb +0 -19
- data/spec/integration_tests/usage_api_spec.rb +0 -29
- data/spec/integration_tests/usage_error_paths_spec.rb +0 -18
- 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 -283
- data/spec/requests/translation_memory/list_spec.rb +0 -27
- 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_spec.rb +0 -35
- data/spec/resources/usage_spec.rb +0 -35
- data/spec/support/live_mock_server.rb +0 -12
- data/spec/support/managed_glossary.rb +0 -17
- data/spec/support/managed_style_rule.rb +0 -17
- data/spec/support/managed_translation_memory.rb +0 -7
|
@@ -23,13 +23,24 @@ module DeepL
|
|
|
23
23
|
"- Error message: #{error_message}"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
##
|
|
27
|
+
# Checks if the translation is done, so the document can be downloaded.
|
|
28
|
+
#
|
|
29
|
+
# @return [Boolean] +true+ if the status is +done+.
|
|
30
|
+
def done?
|
|
31
|
+
status == Constants::DocumentStatusCode::DONE
|
|
32
|
+
end
|
|
33
|
+
|
|
26
34
|
##
|
|
27
35
|
# Checks if the translation finished successfully
|
|
28
36
|
#
|
|
37
|
+
# @deprecated Use #done? instead.
|
|
29
38
|
# @return [true] if so
|
|
30
|
-
|
|
31
39
|
def successful?
|
|
32
|
-
|
|
40
|
+
Deprecation.warn_once('DeepL::Resources::DocumentTranslationStatus#successful?',
|
|
41
|
+
'[DEPRECATION] DeepL::Resources::DocumentTranslationStatus#' \
|
|
42
|
+
'successful? is deprecated, use #done? instead.')
|
|
43
|
+
done?
|
|
33
44
|
end
|
|
34
45
|
|
|
35
46
|
##
|
|
@@ -38,7 +49,15 @@ module DeepL
|
|
|
38
49
|
# @return [true] if so
|
|
39
50
|
|
|
40
51
|
def error?
|
|
41
|
-
status ==
|
|
52
|
+
status == Constants::DocumentStatusCode::ERROR
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
##
|
|
56
|
+
# Checks that the translation has not failed. Also true while it is queued or translating.
|
|
57
|
+
#
|
|
58
|
+
# @return [Boolean] +true+ unless the status is +error+.
|
|
59
|
+
def ok?
|
|
60
|
+
!error?
|
|
42
61
|
end
|
|
43
62
|
|
|
44
63
|
##
|
|
@@ -47,7 +66,7 @@ module DeepL
|
|
|
47
66
|
#
|
|
48
67
|
# @return [true] if so
|
|
49
68
|
def finished?
|
|
50
|
-
|
|
69
|
+
done? || error?
|
|
51
70
|
end
|
|
52
71
|
end
|
|
53
72
|
end
|
|
@@ -8,20 +8,28 @@ module DeepL
|
|
|
8
8
|
class Language < Base
|
|
9
9
|
attr_reader :code, :name
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
# +client:+ is true for a language returned by DeepL::Client. @api private
|
|
12
|
+
def initialize(code, name, supports_formality, *args, client: false)
|
|
12
13
|
super(*args)
|
|
13
14
|
|
|
14
15
|
@code = code
|
|
15
16
|
@name = name
|
|
16
17
|
@supports_formality = supports_formality
|
|
18
|
+
@client = client
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def to_s
|
|
20
22
|
"#{code} - #{name}"
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
# Whether the target language supports the +formality+ option.
|
|
26
|
+
#
|
|
27
|
+
# @return [Boolean, nil] +true+ or +false+ for a target language; for a source language
|
|
28
|
+
# +nil+ if it came from DeepL::Client.
|
|
29
|
+
# @raise [DeepL::Exceptions::NotSupported] For a source language from the module-level
|
|
30
|
+
# +DeepL.languages+, until the next major version.
|
|
23
31
|
def supports_formality?
|
|
24
|
-
return @supports_formality unless @supports_formality.nil?
|
|
32
|
+
return @supports_formality unless @supports_formality.nil? && !@client
|
|
25
33
|
|
|
26
34
|
raise Exceptions::NotSupported, 'Support formality is only available on target languages'
|
|
27
35
|
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] If a pair or TSV line is not exactly two
|
|
40
|
+
# 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 strings 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.is_a?(Array) && pair.size == 2 && pair.all?(String)
|
|
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
|
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
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
module DeepL
|
|
7
7
|
module Resources
|
|
8
8
|
class TranslationMemory < Base
|
|
9
|
-
attr_reader :translation_memory_id, :name, :source_language, :target_languages,
|
|
9
|
+
attr_reader :translation_memory_id, :name, :source_language, :target_languages,
|
|
10
|
+
:segment_count, :creation_time, :updated_time
|
|
10
11
|
|
|
11
12
|
def initialize(translation_memory, *args)
|
|
12
13
|
super(*args)
|
|
@@ -15,11 +16,19 @@ module DeepL
|
|
|
15
16
|
@source_language = translation_memory['source_language']
|
|
16
17
|
@target_languages = translation_memory['target_languages'] || []
|
|
17
18
|
@segment_count = translation_memory['segment_count'] || 0
|
|
19
|
+
@creation_time = parse_time(translation_memory['creation_time'])
|
|
20
|
+
@updated_time = parse_time(translation_memory['updated_time'])
|
|
18
21
|
end
|
|
19
22
|
|
|
20
23
|
def to_s
|
|
21
24
|
"#{translation_memory_id} - #{name}"
|
|
22
25
|
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def parse_time(value)
|
|
30
|
+
Utils::TimeParser.parse_optional_utc_time(value)
|
|
31
|
+
end
|
|
23
32
|
end
|
|
24
33
|
end
|
|
25
34
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
# A translation memory export job. Poll the job until it is finished to obtain the download
|
|
10
|
+
# URL of the exported TMX file.
|
|
11
|
+
|
|
12
|
+
class TranslationMemoryExport < Base
|
|
13
|
+
attr_reader :job_id, :translation_memory_id
|
|
14
|
+
|
|
15
|
+
def initialize(translation_memory_export, reused_existing, *args)
|
|
16
|
+
super(*args)
|
|
17
|
+
parameters = translation_memory_export['parameters'] || {}
|
|
18
|
+
@job_id = translation_memory_export['job_id']
|
|
19
|
+
@translation_memory_id = parameters['translation_memory_id']
|
|
20
|
+
@reused_existing = reused_existing
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# Checks if the API reused a previously completed export instead of starting a new one.
|
|
25
|
+
#
|
|
26
|
+
# @return [true] if so
|
|
27
|
+
|
|
28
|
+
def reused_existing?
|
|
29
|
+
@reused_existing
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def to_s
|
|
33
|
+
"TranslationMemoryExport: ID: #{job_id}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
# A newly created translation memory import job. The TMX file must be uploaded to
|
|
10
|
+
# `upload_url` before `expires_at`, processing starts once the upload is detected.
|
|
11
|
+
|
|
12
|
+
class TranslationMemoryImport < Base
|
|
13
|
+
attr_reader :job_id, :upload_url, :expires_at
|
|
14
|
+
|
|
15
|
+
def initialize(translation_memory_import, *args)
|
|
16
|
+
super(*args)
|
|
17
|
+
@job_id = translation_memory_import['job_id']
|
|
18
|
+
@upload_url = translation_memory_import['upload_url']
|
|
19
|
+
@expires_at = Utils::TimeParser.parse_optional_utc_time(
|
|
20
|
+
translation_memory_import['expires_at']
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_s
|
|
25
|
+
"TranslationMemoryImport: ID: #{job_id}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|