DeepLcom / deepl-node

Official Node.js library for the DeepL language translation API.
MIT License
370 stars 22 forks source link

The API doesn't translate English to Spanish when there's a small typo; it just returns the English text. However, it works for English to French. #50

Closed JavaPr288 closed 5 months ago

JavaPr288 commented 5 months ago

Describe the bug I try to translate Hello darkness my old friend Ive come to talk with you again to Spanish gives Hello darkness my old friend Ive come to talk with you again. However with French and Italian it works correctly

To Reproduce Steps to reproduce the behavior: Use the API To Translate English to Spanish Hello darkness my old friend Ive come to talk with you again to Spanish gives Hello darkness my old friend Ive come to talk with you again.

Expected behavior It should translate to Spanish

Timestamp: 2024-06-25 22:15:42

Error Spanish image

Correct Spanish No Typo image

Working French image

JanEbbing commented 5 months ago

I cant reproduce this (using our python CLI to hit the API):

$ poetry run python -m deepl text --to "ES" "Hello darkness my old friend Ive come to talk with you again"

Hola oscuridad mi viejo amigo he venido a hablar con usted otra vez
JavaPr288 commented 5 months ago

Hi, I realized I was using a context prompt which was correct the problem when I removed the prompt it got resolved.

Thanks for your help!

async function translateText(text, targetLang) {
  try {
    const systemPrompt = "You are a skilled translator. Correct any typos in the English while translating it into Spanish, ensuring the translation is accurate and natural."
    const result = await translator.translateText(text, null, targetLang,{context:systemPrompt});
    console.log("Translated text:", result.text);
  } catch (error) {
    console.error("Error during translation:", error.message);
  }
}

// Example usage

console.log(translateText("Hello darkness my old friend Ive come to talk with you again", "ES"));
JavaPr288 commented 5 months ago

Will close the issue! Removing the context prompt solved the issue. Thanks again for your help!