Problem/Motivation

Currently, text requests sent to the Lara Translate API may exceed 10,000 characters. However, the API enforces a strict limit of 10,000 characters per request. When this limit is exceeded, the API may reject the request or return an error, preventing translation from completing successfully.

To ensure reliability and compliance with the API's requirements, requests must be automatically segmented into chunks of 10,000 characters or fewer before being sent.

Steps to reproduce

  1. Send a text longer than 10,000 characters to the Lara Translate API endpoint.
  2. Observe the error response or failed translation.

Proposed resolution

  • Implement a preprocessing step that splits the input text into segments of a maximum of 10,000 characters.
  • Ensure that segmentation preserves sentence integrity where possible (avoid splitting mid-sentence or mid-word).
  • Send each segment as a separate request to the Lara Translate API and reassemble the translated segments in order.
  • Handle API rate limits and ensure consistent error handling and logging.

Remaining tasks

  • [x] Implement the text segmentation logic based on character count.
  • [x] Update the translation request handler to support multiple API calls per input.
  • [x] Add unit and integration tests for multi-segment translation handling.
  • [x] Verify that long texts are translated correctly and completely.
  • [x] Update documentation to describe the 10,000-character limit and handling logic.

User interface changes

No direct UI changes are required. If a progress indicator or multi-part translation status is visible to the user, it may be updated to reflect segmented processing.

API changes

No changes to the public API are expected. Internal API calls to Lara Translate will now occur in multiple chunks rather than a single request.

Data model changes

No changes to the data model are required.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

robertoperuzzo created an issue. See original summary.

robertoperuzzo’s picture

Title: Enforce 128-word limit per request to Lara Translate API » Enforce 10000-chars limit per request to Lara Translate API
Issue summary: View changes
robertoperuzzo’s picture

Title: Enforce 10000-chars limit per request to Lara Translate API » Enforce 10k-char limit per request to Lara Translate API

robertoperuzzo’s picture

Issue summary: View changes

robertoperuzzo’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.