Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translator exception #42

Open
ReverendThing opened this issue Jan 25, 2024 · 1 comment
Open

Translator exception #42

ReverendThing opened this issue Jan 25, 2024 · 1 comment

Comments

@ReverendThing
Copy link

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.

@JanEbbing
Copy link
Member

JanEbbing commented Jan 25, 2024

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: #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants