Search code examples
google-translategoogle-translation-api

Google.Cloud.Translate.V3 only gives one translation result


I just switched from Google.Cloud.Translate.V2 to Google.Cloud.Translate.V3, expecting to get multiple translation options, but I only get one.

The example code seems geared for it:

    foreach (Translation translation in response.Translations)
    {
       Console.WriteLine($"Translated text: {translation.TranslatedText}");
    }

For example, the Google Translate web page translates the Spanish "Cumplan" with a main translation of English "meet" and other possibilities listed in a pane below, i.e.:

Translations of cumplir
comply
cumplir, consentir, compadecer
fulfill
cumplir, realizar
accomplish
lograr, cumplir, realizar, conseguir, alcanzar, llevar a cabo
satisfy
satisfacer, cumplir, cumplir con, aplacar, contentar, liquidar
etc.

How can I get those additional translations? Is there a way to get the frequency it lists?


Solution

  • The cloud translation API doesn't support all the alternative translations - much to my chagrin - so you can't get them (as of October 2020).

    The support for 'multiple' translations refers to the fact that the API supports your passing a list of strings to be translated, and so can return a response containing the translations for each string you sent it.

    The API supports the translation of fairly large blocks of text, so if it returned a simple list of all the possible translations it would be really long. If there were just three words in the whole text with five possible translations instead of one, you'd have 125 different possibilities. What's needed is a more complex data structure to capture all the reasonable alternatives.

    N.B. there are some existing feature requests around this issue, which you can view and indicate your interest in by 'starring' them here.