Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance translateBatch to Handle Individual Translation Failures (#11) #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nithintejesh
Copy link

Summary

This pull request enhances the translateBatch function to handle individual translation failures gracefully. It ensures that the translation process continues even if some elements fail, and returns an array containing both successful translations and error messages.

Changes

  • Added translateTextSafely function to wrap individual translations with error handling.
  • Modified batchTranslation function to use translateTextSafely for each input text.
  • Ensured that the result array includes both successful translations and error messages.

Issue Reference

This PR addresses issue #11 (Suggestion about translateBatch).

Testing

Tested with various input texts, including invalid ones, to ensure that the batch translation continues processing and returns appropriate results for each text.

Example Output

[
  { "success": true, "translation": "Translated: bonsoir le monde" },
  { "success": true, "translation": "Translated: Hallo Welt" },
  { "success": true, "translation": "Translated: guten morgen" },
  { "success": false, "error": "Invalid text" }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant