microsoft-translator-java-api icon indicating copy to clipboard operation
microsoft-translator-java-api copied to clipboard

Bulk Translation causes crash: Cant cast String to JsonArray

Open mmoayyed opened this issue 12 years ago • 4 comments

What if JSONValue returns a String here? final JSONArray jsonArr = (JSONArray)JSONValue.parse(inputString);

The exception stack I get is the following:

java.lang.Exception: [microsoft-translator-api] Error retrieving translation.
    at com.memetix.mst.MicrosoftTranslatorAPI.retrieveStringArr(MicrosoftTranslatorAPI.java:208)
    at com.memetix.mst.translate.Translate.execute(Translate.java:101)
    at com.memetix.mst.translate.Translate.execute(Translate.java:121)
    at org.jasig.i18n.translate.BingAutoTranslationService.getAutoUpdatedTranslationMap(BingAutoTranslationService.java:47)
    at org.jasig.i18n.translate.AutoTranslateMojo.execute(AutoTranslateMojo.java:121)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to org.json.simple.JSONArray
    at com.memetix.mst.MicrosoftTranslatorAPI.jsonToStringArr(MicrosoftTranslatorAPI.java:261)
    at com.memetix.mst.MicrosoftTranslatorAPI.retrieveStringArr(MicrosoftTranslatorAPI.java:206)

I am translating a String[] array , going from English to Spanish.

This is the contents of my String[]:

[Your password has expired., Please <a href="{0}">change your password</a>., You must change your password., Please <a href="{0}">change your password</a>., Please contact the system administrator to regain access., Please <a href="{0}">change your password</a> now., You will be redirected to your <a href="{0}">application</a> automatically in 10 seconds., Your password expires today!, The supplied service ''{0}'' is not authorized to use CAS, Please try again later., This account has been disabled., Please contact the system administrator to regain access., You cannot login from this workstation., Your password expires in {0} days., Your password expires tomorrow!, You cannot login at this time., Password change date is not specified, has expired or is considered invalid. Please contact the system administrator to regain access.]

mmoayyed avatar Jul 24 '12 20:07 mmoayyed

Good catch. I'll try to get a fix for this soon and push it into a 0.6.2-SNAPSHOT

boatmeme avatar Jul 28 '12 16:07 boatmeme

Even I 'm facing the same issue. getting crashed when trying to translate bulk data.

santho090 avatar Dec 06 '12 07:12 santho090

When texte to translate content \n (newline) or " (quote) im receive the same error

pascalmartin avatar May 16 '13 20:05 pascalmartin

I am facing the same issue, any solution please?

ankitchhabraindia avatar Jan 03 '14 06:01 ankitchhabraindia