Skip to content

v4.0.0

Latest

Choose a tag to compare

@github-actions github-actions released this 24 Nov 12:10
· 5 commits to main since this release

Added

  • Added v2 glossaries to DeepL::Client: create_glossary(name, source_lang, target_lang, entries, **options), create_glossary_from_csv(name, source_lang, target_lang, csv, **options), list_glossaries, get_glossary(glossary), get_glossary_entries(glossary),
    delete_glossary(glossary) and get_glossary_languages. A glossary argument is an ID or a
    DeepL::Resources::Glossary; the entries are returned as a hash and delete_glossary returns
    nil. Please refer to the README for usage instructions.
  • Added the migration guide Upgrading to 4.0.0, which lists every breaking
    change of this release with before and after code.

Changed

  • Breaking: DeepL::Client#create_translation_memory_import and
    #import_translation_memory_from_filepath take the keyword extra_body_parameters: instead
    of **options. Migration: send fields the library does not model with extra_body_parameters:;
    any other option raises ArgumentError.
  • Breaking: Every DeepL::Client method that takes options accepts only the options it documents. Any
    other option, also a misspelled one, raises ArgumentError naming it before a request is sent.
    Previously, text translation, rephrasing, correction and the glossary, spoken terms, style rule
    and style profile methods sent it as a body field, and document translation and translation
    memory import dropped it. This includes show_billed_characters (always sent as true) and
    glossary_id for text translation. Migration: fix misspelled options, and send fields the
    library does not model with extra_body_parameters:.
  • Breaking: DeepL::Resources::Usage#any_limit_reached? is replaced by #any_character_limit_reached?.
    It returns true if the account's character limit (character) or this API key's character
    limit (api_key_character) is reached; the speech minutes are not considered. Migration:
    rename the call; check the speech minute details with limit_reached? directly.
  • Breaking: Ruby 3.0 or later is now required; the gem declares required_ruby_version >= 3.0. Migration:
    on Ruby 2.x, upgrade to Ruby 3.0 or later, or stay on deepl-rb 3.x.
  • Breaking: Network failures always raise DeepL::Exceptions::ConnectionError, with the original error as
    cause; the removed module-level API raised the original error. Migration: rescue
    DeepL::Exceptions::ConnectionError (or DeepL::Exceptions::Error).
  • Breaking: DeepL::Resources::Language#supports_formality? returns nil for a source language; the
    removed DeepL.languages raised DeepL::Exceptions::NotSupported. Migration: check for nil.
  • Breaking: DeepL::Resources::StyleRule#configured_rules returns the hash the API sends (category ->
    rule -> value, string keys) instead of a DeepL::Resources::ConfiguredRules object, so
    categories beyond the seven fixed readers are kept and absent categories are not filled with
    {}. Migration: replace configured_rules.numbers with
    configured_rules.fetch('numbers', {}), likewise for the other categories.
  • Breaking: DeepL::Resources::TranslationMemoryJob#finished? (and TranslationMemoryJobResult#finished?)
    is [secure] for the status downloaded, which the API does not send, so
    wait_until_translation_memory_job_done keeps polling on it instead of returning the job.
    Migration: none for jobs the API returns; code that built a job with status downloaded itself
    should use completed.
  • Breaking: Requests that create a resource are retried only when the request was not processed: after
    HTTP 429 and transient network failures while connecting, before the request is sent, such as DNS
    resolution errors, refused connections, unreachable hosts or networks, connection timeouts and
    resets during the TLS or proxy handshake. create_developer_key already was for DNS resolution
    errors, refused connections and connection timeouts. This covers create_glossary,
    create_glossary_from_csv, create_multilingual_glossary,
    create_multilingual_glossary_from_csv, create_spoken_terms, create_style_rule,
    create_style_rule_custom_instruction, create_style_profile, the document upload of
    translate_document and translate_document_upload, and the job creation of
    create_translation_memory_import, create_translation_memory_export,
    import_translation_memory_from_filepath and export_translation_memory_to_filepath. Previously
    they were also retried after any 5xx reply and every other transient network failure, so a retry
    could create a second resource. A 5xx reply now raises DeepL::Exceptions::ServerError with
    should_retry? [secure] at once. Migration: if you retry these calls yourself, check first whether
    the resource was created.
  • Breaking: A DeepL::Exceptions::ConnectionError of a request that creates a resource,
    create_developer_key included, has should_retry? true when the response failed after its
    headers arrived (body cut off before its Content-Length, reset or read timeout), and the
    library does not retry it; in 3.10.0 create_developer_key raised it with should_retry?
    [secure] and the other create requests retried it, and a connection closed before the response
    now has should_retry? [secure]. Migration: if you retry on should_retry?, check first
    whether the resource was created.
  • Breaking: DeepL::Exceptions::ValidationError is now an ArgumentError instead of a
    DeepL::Exceptions::Error, so rescue ArgumentError catches every invalid argument, also an
    invalid glossary or spoken terms term or a malformed glossary entry. Migration: rescue
    ArgumentError (or DeepL::Exceptions::ValidationError) instead of DeepL::Exceptions::Error
    for these. It no longer has http_status_code or should_retry?, and its constructor takes
    only a message.
  • Breaking: The translation memory methods raise ArgumentError instead of DeepL::Exceptions::Error
    for an empty translation memory ID or job ID (or a TranslationMemory or
    TranslationMemoryJob without one) and an empty upload URL. An export job with an empty or no
    download URL still raises DeepL::Exceptions::Error. Migration: rescue ArgumentError for
    these.
  • Breaking: The multilingual glossary methods raise ArgumentError before any request for an empty
    glossary ID or a MultilingualGlossary without one (previously sent to /v3/glossaries/), an
    empty name (create_multilingual_glossary, create_multilingual_glossary_from_csv,
    update_multilingual_glossary_name), an empty source_lang or target_lang of
    delete_multilingual_glossary_dictionary, an empty dictionaries array of
    create_multilingual_glossary, and a dictionary whose entries (not given as CSV) are empty.
    Migration: pass a non-empty value; these calls previously failed at the API or sent an empty
    value.
  • Breaking: The spoken terms and style rule methods raise ArgumentError before any request for an empty
    ID or a SpokenTerms, StyleRule or CustomInstruction without one. Previously the request
    was sent to /v3/spoken-terms/ or /v3/style_rules/, and a nil instruction ID of
    get_style_rule_custom_instruction, update_style_rule_custom_instruction and
    delete_style_rule_custom_instruction dropped the path segment. Migration: pass a non-empty ID.
  • Breaking: create_style_rule, update_style_rule_name, create_style_rule_custom_instruction and
    update_style_rule_custom_instruction raise ArgumentError before any request for an empty
    name, language, label or prompt. Migration: pass a non-empty value.
  • Breaking: translate_text and rephrase_text raise ArgumentError before any request for an empty
    text: an empty string, an empty array or an array with an empty string, as correct_text
    already did. Migration: drop empty texts before the call.
  • Breaking: translate_text, translate_document and translate_document_upload raise ArgumentError
    before any request for an empty or nil target_lang, an empty source_lang (pass nil to
    detect it), and a translation_memory_threshold set without translation_memory or outside
    0 to 100 (translate_document wraps it in DeepL::Exceptions::DocumentTranslationError).
    Document translation with the glossary option now requires source_lang like
    glossary_ids. Migration: pass valid values; these calls previously sent
    the value and failed at the API, or ignored the threshold.
  • Breaking: translate_text, translate_document and translate_document_upload raise
    ArgumentError before any request when glossary, style_rule, style_profile or
    translation_memory is an empty ID or a resource object without its ID, or when glossary_ids
    has an empty entry or a glossary without its ID (translate_document wraps it in
    DeepL::Exceptions::DocumentTranslationError). They were sent as an empty or null field, or
    left out (a glossary object without its ID), and failed at the API or were ignored. nil for
    one of the four options still leaves it unset.
    Migration: pass a non-empty ID or a resource object returned by the API.
  • Breaking: translate_document raises DeepL::Exceptions::DocumentTranslationError (with
    document_handle nil and the ArgumentError as cause) for an unknown option, which
    3.10.0 dropped, and checks before the upload that the directory of output_path exists and is
    writable; previously the document was uploaded and translated and the download failed. A
    missing input file still raises ArgumentError. Migration: rescue
    DeepL::Exceptions::DocumentTranslationError.
  • Breaking: translate_document_download no longer overwrites an existing file. Before the request it
    raises Errno::EEXIST if output_path exists and Errno::ENOENT or Errno::EACCES if its
    directory is missing or not writable. Migration: delete the file first or pass a new path.
  • Breaking: download_translation_memory_export no longer overwrites an existing file: before the request
    it raises Errno::EEXIST if output_path exists and Errno::ENOENT or Errno::EACCES if its
    directory is missing or not writable. A failure writing the file now raises the Errno error
    instead of DeepL::Exceptions::Error. Migration: delete the file first or pass a new path, and
    rescue SystemCallError.
  • Breaking: export_translation_memory_to_filepath no longer overwrites an existing file: it raises an
    error (DeepL::Exceptions::TranslationMemoryJobError, see below) before creating the export
    job if output_path exists or its directory is not writable, as it already did for a missing
    directory. Migration: delete the
    file first or pass a new path.
  • Breaking: create_translation_memory_import raises ArgumentError before any request for an empty
    file_name or a content_length that is not positive, and
    import_translation_memory_from_filepath rejects an empty input file before any request
    (DeepL::Exceptions::TranslationMemoryJobError, see below); previously the import job was
    created. Migration: pass a non-empty file.
  • Breaking: The messages of AuthorizationFailed, RequestEntityTooLarge, LimitExceeded,
    QuotaExceeded and ServerError now end with the API's error message from the response
    body (<fixed text>: <API message>), as the other HTTP errors already did; without one the
    fixed text stays. The RequestEntityTooLarge message no longer claims a limit of 50 text
    parts. Migration: code that compares these messages should check the error class instead.
  • Breaking: import_translation_memory_from_filepath and export_translation_memory_to_filepath wrap
    every failure except a missing input file in the new
    DeepL::Exceptions::TranslationMemoryJobError (a DeepL::Exceptions::Error), with the
    original error as cause. Its job_id is the ID of the job, set as soon as the job was
    created; its job is the last TranslationMemoryJob status fetched, nil before the first
    status check. http_status_code and should_retry? are copied from a DeepL error cause.
    Previously the underlying error was raised (DeepL::Exceptions::Error or one of its
    subclasses). Migration: rescue
    DeepL::Exceptions::TranslationMemoryJobError (or DeepL::Exceptions::Error) and inspect
    cause, job_id and job.
  • Breaking: DeepL::AdminClient#set_developer_key_usage_limits raises ArgumentError naming the keyword
    for any limit keyword other than characters:, speech_to_text_milliseconds: and
    speech_to_speech_milliseconds: (also key_id:), before a request is sent. Previously any
    keyword was sent as a body field, so a misspelled limit such as character: 0 changed
    nothing. Migration: fix misspelled limits; send other fields with extra_body_parameters:.
  • Breaking: DeepL::Client#download_translation_memory_export no longer accepts a download URL
    string, only the DeepL::Resources::TranslationMemoryJob; a string raises NoMethodError.
    Migration: pass the job returned by
    wait_until_translation_memory_job_done instead of job.result.download_url.
  • Breaking: DeepL::Client.new, DeepL::AdminClient.new and the proxy of
    DeepL::HTTPClientOptions accept a proxy URL only with the http or https scheme and raise
    ArgumentError for any other scheme, a missing one included (e.g. socks5://, //host:port).
    An https proxy URL is now connected to over TLS. It needs net-http 0.5.0 or later (bundled
    from Ruby 3.4) and an https server URL, and raises ArgumentError otherwise. Previously any
    scheme was accepted and the proxy, an https one included, was used as a plain HTTP proxy, so
    its credentials were sent unencrypted. Net::HTTP does not verify the certificate of an https
    proxy. A proxy URL with an empty host (http://, http://:8080) and a proxy hash with a blank
    proxy_addr also raise ArgumentError; they were accepted, and an empty host connected to the
    local machine on some platforms. Migration: use http:// for a plain HTTP proxy; for an
    https proxy on Ruby 3.0-3.3, add gem 'net-http', '>= 0.5'; give the proxy a host.
  • Breaking: DeepL::AdminClient#create_developer_key is now retried after every transient
    network failure raised while connecting, before the request is sent: besides DNS resolution
    errors, refused connections and connection timeouts also an unreachable host or network,
    Errno::ETIMEDOUT, Errno::ECONNRESET or Errno::ECONNABORTED from connect, and a reset during
    the TLS or proxy handshake. The same errors on an established connection are not retried. It
    raised DeepL::Exceptions::ConnectionError with should_retry? [secure] at once before. The other
    requests that create a resource already retried these failures in 3.10.0 and still do.
    Migration: none needed; code that retries create_developer_key itself after such an error now
    sees the library's retries first.
  • Breaking: the multilingual glossary methods that take a dictionary
    (create_multilingual_glossary, ..._from_csv, update_multilingual_glossary,
    update_multilingual_glossary_dictionary, replace_multilingual_glossary_dictionary) and
    get_multilingual_glossary_dictionary_entries raise ArgumentError before any request for a
    nil or empty source_lang or target_lang; create_spoken_terms, update_spoken_terms,
    replace_spoken_terms_list, get_spoken_terms_entries and delete_spoken_terms_list for a nil
    or empty lang; and create_style_rule_custom_instruction,
    update_style_rule_custom_instruction and the custom_instructions of create_style_rule for an
    empty source_language (nil still leaves it out). They sent the request with the empty or
    null language and the API rejected it. Migration: pass the language, or nil where it is
    optional; rescue ArgumentError instead of the API error.
  • Breaking: DeepL::Client.new and DeepL::AdminClient.new treat nil for max_retries:,
    timeout: and send_platform_info: as the default (5, 10 seconds, true), like an omitted
    keyword. Previously timeout: nil used Net::HTTP's 60-second timeouts and
    send_platform_info: nil left the OS and Ruby versions out of the User-Agent. Migration:
    pass send_platform_info: [secure] to leave them out.
  • Breaking: the library no longer checks argument types by hand. app_info: of a type other
    than DeepL::AppInfo or a hash no longer raises ArgumentError, and a glossary entry whose
    terms are not strings (for example { 'a' => 1 }) no longer raises
    DeepL::Exceptions::ValidationError; such a value fails as Ruby fails or is sent as its string
    form. Value checks are unchanged: an entry that is not two terms, an empty or invalid term and
    a duplicate source term still raise DeepL::Exceptions::ValidationError. Migration: pass the
    documented types.
  • Breaking: DeepL::Client#get_multilingual_glossary_dictionary_entries raises
    DeepL::Exceptions::NotFound with http_status_code nil and response nil if the API
    answers HTTP 200 with no entries for the language pair; the error carried that response and
    status 200 before. The message is unchanged. The API answers a missing dictionary with HTTP
    404, which raises DeepL::Exceptions::NotFound with status 404 and the response, as before.
    Migration: code that read http_status_code or response of this error checks the error
    class instead.
  • Breaking: DeepL::Client#translate_document_upload raises Errno::EISDIR before any
    request when input_path is a directory; it raised DeepL::Exceptions::ConnectionError after
    connecting before. Migration: rescue SystemCallError for unreadable input paths.
  • Breaking: DeepL::Client#create_multilingual_glossary, #update_multilingual_glossary,
    #update_multilingual_glossary_dictionary and #replace_multilingual_glossary_dictionary raise
    ArgumentError before any request when a dictionary hash gives its entries as an empty or
    whitespace-only CSV string (entries_format: 'csv'). Previously the request was sent and the
    API rejected it. #create_multilingual_glossary_from_csv is unchanged.
    Migration: pass a non-empty value; rescue ArgumentError instead of the API error.
  • Breaking: DeepL::Client#rephrase_text and #correct_text raise ArgumentError before a request when
    target_lang is an empty string. Previously '' was sent. nil still keeps the language of
    the text.
    Migration: pass a non-empty value; rescue ArgumentError instead of the API error.
  • Breaking: DeepL::Client#update_multilingual_glossary_dictionary_from_csv and
    #replace_multilingual_glossary_dictionary_from_csv raise ArgumentError before a request
    when the CSV content (after reading an IO) is empty or whitespace only. Previously it was sent.
    Migration: pass a non-empty value; rescue ArgumentError instead of the API error.

Removed

  • Breaking: DeepL::Resources::TranslationMemoryJobResult::STATUS_DOWNLOADED. downloaded is not a job
    status of the API. Migration: compare with STATUS_COMPLETED (or call done?) instead.
  • Breaking: DeepL::Resources::ConfiguredRules. StyleRule#configured_rules is now a hash (see Changed).
    Migration: read the categories from the hash.
  • Breaking: The glossary_id option of text translation (DeepL::Client#translate_text,
    DeepL.translate), deprecated in 3.10.0. Use glossary instead, which takes the glossary ID or
    a glossary object. glossary_id now raises ArgumentError like any other unknown option.
  • Breaking: The glossary_id option of document translation (DeepL::Client#translate_document,
    #translate_document_upload, DeepL.document.upload), deprecated in 3.10.0. Use glossary
    instead. glossary_id now raises ArgumentError like any other unknown option.
  • Breaking: DeepL::Resources::Usage#character_count, #character_limit and #quota_exceeded?,
    deprecated in 3.10.0. Use character.count, character.limit and
    character.limit_reached? (or any_character_limit_reached?) instead.
  • Breaking: DeepL::Resources::Usage#document and #team_document: the API no longer returns them.
    document_* and team_document_* fields in a usage response are ignored. Migration: drop
    these reads.
  • Breaking: DeepL::Resources::DocumentHandle#wait_until_document_translation_finished, deprecated in
    3.10.0. Use DeepL::Client#translate_document_wait_until_done, which raises
    DeepL::Exceptions::Error with the API's message if the translation fails or timeout_s
    expires.
  • Breaking: DeepL::Resources::DocumentTranslationStatus#successful?, deprecated in 3.10.0. Use #done?
    instead.
  • Breaking: The module-level API, deprecated in 3.10.0: DeepL.configure, DeepL.configuration,
    DeepL.api, DeepL.http_client and DeepL.with_session, with the global configuration and
    connection, its DEEPL_AUTH_KEY and DEEPL_SERVER_URL fallbacks and its 60-second default
    timeout. Create a DeepL::Client instead, see "Migrating from the module-level API" in the
    README: DeepL::Client.new(auth_key, server_url:, headers:, max_retries:, timeout:, proxy:, send_platform_info:, app_info:, http_client_options:, logger:). The client reads no
    environment variables and defaults to a 10-second timeout.
  • Breaking: DeepL::Configuration is no longer public, and version= and max_doc_status_queries= are
    removed with it. Pass the options to DeepL::Client.new.
  • Breaking: DeepL.translate. Use DeepL::Client#translate_text, which returns an array for an array of
    texts, also for a one-element array.
  • Breaking: DeepL.rephrase. Use DeepL::Client#rephrase_text(text, target_lang, writing_style:, tone:),
    which returns an array for an array of texts and does not send options set to nil.
  • Breaking: DeepL.usage. Use DeepL::Client#get_usage.
  • Breaking: DeepL.languages. Use DeepL::Client#get_source_languages or #get_target_languages.
  • Breaking: DeepL.document and DeepL::DocumentApi. Use DeepL::Client#translate_document (returns the
    final DocumentTranslationStatus instead of the number of bytes written, and raises
    ArgumentError for a missing input file), #translate_document_upload (filename: keyword),
    #translate_document_get_status, #translate_document_wait_until_done and
    #translate_document_download (returns nil).
  • Breaking: DeepL.style_rules and DeepL::StyleRuleApi. Use the style rule methods of
    DeepL::Client (get_all_style_rules, create_style_rule, ...). They take source_language:
    as a keyword and the delete methods return nil.
  • Breaking: DeepL.translation_memories and DeepL::TranslationMemoryApi. Use the translation memory
    methods of DeepL::Client (list_translation_memories, ...). A missing input file raises
    ArgumentError, other local file failures raise DeepL::Exceptions::Error, and a non-2xx
    reply of a storage URL raises DeepL::Exceptions::Error with http_status_code.
  • Breaking: DeepL.glossaries and DeepL::GlossaryApi. Use the v2 glossary methods of DeepL::Client:
    create becomes create_glossary (entries as a hash; for CSV use
    create_glossary_from_csv), list list_glossaries, find get_glossary, entries
    get_glossary_entries (returns a hash of source term to target term instead of pairs),
    destroy delete_glossary (returns nil instead of the ID) and language_pairs
    get_glossary_languages.
  • Breaking: Per-call additional HTTP headers. Use the headers: option of DeepL::Client.new.
  • Breaking: DeepL::Exceptions::NotSupported, deprecated in 3.10.0. Nothing raises it any more.
    Migration: drop the rescue; Language#supports_formality? returns nil instead (see Changed).

Fixed

  • DeepL::Client.new and DeepL::AdminClient.new remove trailing slashes from server_url, so a
    URL ending in / no longer makes every request go to a //v2/... or //v3/... path, which the
    API does not serve (HTTP 301 or 404), and inspect shows the URL without the slash.
  • Breaking: DeepL::Client.new and DeepL::AdminClient.new accept the proxy as a URI and as a hash
    with symbol keys (proxy_addr:, proxy_port:), and raise ArgumentError for any other proxy
    value, such as a hash without both keys. Previously such a proxy was ignored without an error
    and the client connected directly. The same applies to the proxy of
    DeepL::HTTPClientOptions. Migration: pass a proxy URL, or a hash with both proxy_addr and
    proxy_port.
  • Breaking: DeepL::Client.new and DeepL::AdminClient.new raise ArgumentError naming server_url
    when it is not an absolute http or https URL with a host (e.g. localhost:3000,
    ftp://x.test or ''). Previously the client was built and failed on the first request, or
    URI::InvalidURIError was raised. Migration: pass the full URL, e.g.
    http://localhost:3000.
  • DeepL::Client#translate_document_upload (and #translate_document): a nil value in
    extra_body_parameters removes the form field of that name, the library's own field included.
    Previously it was sent as an empty field. JSON request bodies still send nil as null.
  • DeepL::Client#create_translation_memory_export (also used by
    #export_translation_memory_to_filepath) sends the export request without a body or
    Content-Type (Content-Length: 0), as the API defines it. Previously it sent {} as a JSON
    body.
  • The gem no longer contains the specs (spec/), .gitlab-ci.yml and license_checker.sh.