0

I want to use the google translate API to detect a language being typed and also get the translation but it seems this is not possible according to the docs here.

Does anyone know if this is possible? Or would I have to make two calls? Thanks

cbutler
  • 1,111
  • 5
  • 16
  • 32
  • Looks you can detect and translate at the same time: https://cran.rstudio.com/web/packages/googleLanguageR/vignettes/translation.html – JL-HaiNan Mar 06 '18 at 00:05
  • Basically it will detect the source language automatically by calling the API method translate(): https://cloud.google.com/translate/docs/translating-text – JL-HaiNan Mar 06 '18 at 00:11
  • Ahhhh! Thanks JL-HN! It seems you only get detectedSourceLanguage back as a field if you do not supply the source as a parameter. Not sure how I missed this. I would certainly accept your comment as an answer to this. – cbutler Mar 06 '18 at 06:49

2 Answers2

2

Definitely you can detect and translate your contents at the same time. To be more specific, it will detect the source language automatically without specifying the source language by simply calling the Translation API method translate().

JL-HaiNan
  • 1,004
  • 9
  • 20
  • Thanks guys. I tried this out and its working great :) . I just needed to leave source out of the query url. – cbutler Mar 07 '18 at 18:40
1

You can directly call the translate method without specifying the source language and only specify target language. Below is code snippet of code using google-cloud-translate jar. It works perfect

    Translate translate = getTranslationServiceClient();

    // Translates some text into target language
    Translation translation = translate.translate("Hello", TranslateOption.targetLanguage("hi"));