Skip to content

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