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

Translator exception

Open ReverendThing opened this issue 1 year ago • 1 comments

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);
        }
  1. Call the translation function as follows: TextResult t= TranslateText(speech.OriginalText).Result;

  2. 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.

ReverendThing avatar Jan 25 '24 04:01 ReverendThing

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.

JanEbbing avatar Jan 25 '24 10:01 JanEbbing