DeepLcom / deepl-dotnet

Official .NET library for the DeepL language translation API.
MIT License
168 stars 23 forks source link

Translator exception #42

Open ReverendThing opened 5 months ago

ReverendThing commented 5 months ago

If I use the example code given in the readme then I get an error that the language code "en" is deprecated and to use "en-GB" instead, however, if I try and change to this then my program hangs indefinitely.

Steps to reproduce the behavior:

  1. Use the following as a translation function:

       static public async Task<TextResult> TranslateText(string originalText)
        {
            return await translator.TranslateTextAsync(originalText, LanguageCode.Norwegian, LanguageCode.English);
        }
  2. Call the translation function as follows: TextResult t= TranslateText(speech.OriginalText).Result;

  3. Receive error "One or more errors occurred. (targetLanguageCode="en" is deprecated, please use "en-GB" or "en-US" instead)"

I have tried changing my translation function as follows: return await translator.TranslateTextAsync(originalText, LanguageCode.Norwegian, "en-GB"); And this causes the program to hang indefinitely.

JanEbbing commented 5 months ago

Edit: Sorry I didnt see the .Result at the end of your lines, I corrected my answer.

Hi, thanks for reaching out!

there is maybe a related issue here: https://github.com/DeepLcom/deepl-dotnet/issues/15 How are you executing this code? In Visual Studio with its runner? Via console with dotnet run? Would be great to have a reproducible example for this.

Regarding the en language code being deprecated, could you point to where in the README you found this snippet? en is deprecated as a target language code, but I can only find it as a source language code in the readme (which is allowed)

Wrong previous answer:

Your TranslateText is still async, and returns a Task<TextResult>, not a TextResult.

Changing TextResult t= TranslateText(speech.OriginalText).Result; to TextResult t = await TranslateText(speech.OriginalText).Result;

should fix your hanging issue. We don't currently offer a synchronous way to get translation results in the library.