deepl-node icon indicating copy to clipboard operation
deepl-node copied to clipboard

Innacurate source language detection

Open LuisC360 opened this issue 1 year ago • 0 comments

I don't know why this happens, but when I try to get the source language of a small snippet of text, it always gives me an innacurate source language code.

To Reproduce

const { Translator } = require('deepl-node');

const apiKey = process.env.DEEPL_API_KEY;
const translator = apiKey ? new Translator(apiKey) : null;

// Assume text === "Paso uno", source language is Spanish ('es')
async function getSourceLanguage(text) {
   if (!translator) {
      return 'en';
   }

  try {
    const translation = await translator.translateText(text, null, target_lang='EN-GB');
    return translation.detectedSourceLang; // Got Italian ('it') as the detected source language
  } catch (error) {
    console.error('DeepL API error: ', error);
  }
}

Expected behavior The function should return 'es' for the assumed input

Additional context Library version "^1.14.0"

LuisC360 avatar Dec 20 '24 19:12 LuisC360