0

When trying to access google translate api from an android application it gives the following error:

java.lang.RuntimeException: An error occurred while executing doInBackground()
....
Caused by: com.google.cloud.translate.TranslateException: Invalid Value
...
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid Value",
"reason" : "invalid"
} ],
"message" : "Invalid Value"

The code inside doInBackground method() is:

 Translate translate = TranslateOptions.newBuilder()
                .setApiKey("myAPI_key").build().getService();

        Translation translation = translate.translate(
                params[0],
                Translate.TranslateOption.sourceLanguage("en"),
                Translate.TranslateOption.targetLanguage("al"));


        return translation.getTranslatedText();                                                }

The string I pass is in english. Can anyone help me figuring out this error? Thanks in advance.

IldiX
  • 591
  • 1
  • 7
  • 16

1 Answers1

0

Your problem is in the line:

Translate.TranslateOption.targetLanguage("al"));

al is not a correct code for any supported language.

You can check the complete list of supported languages in the Google APIs Explorer.

dsesto
  • 7,864
  • 2
  • 33
  • 50