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
- Send a text longer than 10,000 characters to the Lara Translate API endpoint.
- 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.
Issue fork tmgmt_laratranslate-3552783
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
Comment #2
robertoperuzzoComment #3
robertoperuzzoComment #5
robertoperuzzoComment #7
robertoperuzzo