Code Monkey home page Code Monkey logo

microsoft-translator-java-api's Introduction

microsoft-translator-java-api


Provides a Java wrapper around the Microsoft Translator API aka Bing Translator.

Created in an attempt to fill the void left by the deprecation of the Google Translate API announced on May 26, 2011 and scheduled for permanent shutdown on December 1, 2011.

In an effort to lessen the impact on Java developers that have previously integrated the Google Translate API into their applications, it is my goal to mimic the code structure, naming conventions, functionality, and usage patterns of the excellent and widely used google-api-translate-java by Rich Midwinter.

Requires

  • Java 1.5 or greater
  • A Windows Azure Marketplace Client ID and Client Secret - Documentation

Please note: If you signed up for a Bing Developer Key after March 31, 2012, you will not be able to use your App Id with this API. Please visit the aforementioned documentation link

Quickstart

Download the latest JAR with Dependencies

import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;

public class Main {
  public static void main(String[] args) throws Exception {
    // Set your Windows Azure Marketplace client info - See http://msdn.microsoft.com/en-us/library/hh454950.aspx
    Translate.setClientId(/* Enter your Windows Azure Client Id here */);
    Translate.setClientSecret(/* Enter your Windows Azure Client Secret here */);

    String translatedText = Translate.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);

    System.out.println(translatedText);
  }
}

More Examples

I've posted some examples to the SVN repository on Google Code. The examples include:

Maven

For those using Maven 2 to manage their project dependencies, the microsoft-translator-java-api is distributed via the Maven Central repository. Simply include the following in your POM.xml to use the Microsoft Translator Java API:

<dependency>
    <groupId>com.memetix</groupId>
    <artifactId>microsoft-translator-java-api</artifactId>
    <version>0.6.2</version>
    <type>jar</type>
</dependency>

Or, if you're feeling adventurous, help us test the next version by adding the latest SNAPSHOT to your POM.xml:

<dependency>
    <groupId>com.memetix</groupId>
    <artifactId>microsoft-translator-java-api</artifactId>
    <version>0.7-SNAPSHOT</version>
    <type>jar</type>
</dependency>

The SNAPSHOT is hosted at the Sonatype OSS Snapshot repository, so if you do not already have it in your repository list, you will need to add this also

<repository>
    <id>sonatype-oss-repo</id>
    <name>Sonatype Open Source maven snapshot repo</name>
    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>

Support on Beerpay

Contributions to the 🍻 fund are much appreciated!

Beerpay Beerpay

License

The microsoft-translator-java-api is licensed under the Apache License, Version 2.0

/*
 * Copyright 2011-2015 Jonathan Griggs.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Please note that while this license does not distinguish between personal, internal or commercial use, the Microsoft Translator API itself does in fact make this distinction.

If you intend to use the Microsoft Translator API for commercial or high volume purposes, you would need to sign a commercial license agreement and provide your appID to the Microsoft Translator team. For more details contact [email protected]. This allows the Microsoft Translator team to better tune the service to the needs of our many partners, and avoid abuse.

microsoft-translator-java-api's People

Contributors

boatmeme avatar rmtheis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

microsoft-translator-java-api's Issues

Translate.execute() sometimes returns a NullPointerException on Android 4.0

If you try to run Microsoft Translator Java API on Android 4.0, you must make execute all network calls on either a separate thread, or explicitly set the ThreadPriority to LAX.

This would all be easier to diagnose if MST-Java API didn't get a NullPointerException from Android's networking when trying to getInputStream() on HttpUrlConnection in order to close it.

Return DetectedLanguage when Translating

In the case when you are asking the API to auto-detect the from language, it is useful to know what the auto-detected language was. Can this be added to the package?

Wrong translations

Hi All,

I have some weird translations that Bing gives back. First, the online Bing translator and the API do not give back the same translation. For instance '23p' in English translate to '122' in French. Why?

Also there is some bug in both the online translator and the api for this term 'Debranching enzyme' (in English) that translates to '??Monder enzymatique' in French. Also online the ?? are shown.

Implement Unit Test Suite for various versions of Android

We've encountered so many Android specific issues, it would be worth our while to invest some time in analysis and implementation of an Android Unit Test suite, preferably for different versions of the platform.

This may end up as an external project, unless it makes sense to add it to this code base.

Error message

I have BT.java:

import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;

public class BT {
public static void main(String[] args) throws Exception {
//Replace client_id and client_secret with your own.
Translate.setClientId("shengday");
Translate.setClientSecret("goVdIz/l8fgAwWqYWdzK4RuHKloNoZ5Y5LFO7zMUEno");

// Translate an english string to spanish
String englishString = "Hello World!";
String spanishTranslation = Translate.execute(englishString, Language.SPANISH);

System.out.println("Original english phrase: " + englishString);
System.out.println("Translated spanish phrase: " + spanishTranslation);

}
}

On Windows I compiled with "javac -cp .\microsoft-translator-java-api-0.6.2-jar-with-dependencies.jar BT.java", where microsoft-translator-java-api-0.6.2-jar-with-dependencies.jar is downloaded from here.

Then I tried to run "java BT" and got the error message below, what did I do wrong?

Exception in thread "main" java.lang.NoClassDefFoundError: com/memetix/mst/translate/Translate
at BT.main(BT.java:7)
Caused by: java.lang.ClassNotFoundException: com.memetix.mst.translate.Translate
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more

Exception [microsoft-translator-api] Error retrieving translation : Connection refused: connect

Trying to use below for translation -

Translate.setClientId(clientId);
Translate.setClientSecret(clientSecret);
String translatedText = Translate.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);

System.out.println(translatedText);

Jars used - microsoft-translator-java-api-0.6.1-jar-with-dependencies.jar
But in execute call, getting exception for openConnection.

Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
at com.memetix.mst.MicrosoftTranslatorAPI.getToken(MicrosoftTranslatorAPI.java:133)
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveResponse(MicrosoftTranslatorAPI.java:160)
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:199)
... 3 more

Generate jar from project

Hello, It seems that the latest jar (SNAPSHOT 4.0) doesn't have the (java.lang.string.isEmpty) fix... and I couldn't open the project in eclipse (It didn't recognize it)...so
Is there a jar with the latest updates? or..
How can I open the project in eclipse so I can generate a Jar file for the latest version

Keep Getting TranslateApiException

I created an account on the Azure Marketplace (free account for up to 2,000,000 characters per month) and created an application for that account that shows as active with my client_id and client_secret.

I have downloaded the .jar file with dependencies.

I used the following code:

public static final String client = "xxxxxxxxxxxx"; // replaced by the actual value
public static final String secret = "xxxxxxxxxxxxx"; // replaced by the actual value

Translate.setClientId(client);
Translate.setClientSecret(secret);
Language from = Language.fromString(fromLanguage);
Language to = Language.fromString(toLanguage);
if (from != null && to != null) {
String textString = Translate.execute(toTranslate, from, to);
...
}
else {
...
}

This code is used to automatically translate the text for buttons/menu options, etc. within my program. I also locally store these values so a translation for a specific text/language needs only be performed once.

My first time running the program I got translations for the first 20 or so items, then everything after that the text was returned as:

"TranslateApiException: Cannot find an active Azure Market Place Translator Subscription associated with the request credentials. : ID=1035.V2_Json.Translate.227EAA79"

Obviously for each request the ID= had a different ending key.

I translated much less than 2,000,000 characters. Any ideas why this worked for about 10 seconds and then stopped? Any help would be appreciated.

Best Regards,

Language detection error still returns 200 ok status

The following text can be translated into English from either Serbian or Bulgarian (I believe it's actually Serbian):

"Хелло ми наме ис Драгон"

Because of this, when the language is set to "autodetect", the translated String returned is:

"ArgumentOutOfRangeException: 'from' must be a valid language. {...}
(including the leading ")

Despite this error, a 200 ok status is still returned and so the API returns the "ArgumentOutOfRangeException" thinking it's the valid translated String.

Further information on this error is here - http://social.msdn.microsoft.com/Forums/en-US/5c76aac1-6d28-49ac-8f96-5f66c47b35bc/translate-error-via-soap?forum=microsofttranslator - but unhelpfully it looks like there are other types of Exceptions that can be returned in this manner.

shoud allow the setting of the content-type... it is now hardcoded into the class to plain/text , which is not good

You should allow the setting of the content-type... it is now hardcoded into the class to plain/text , which is not good. One should be able to set it as it wishes.

This is a problem description:

http://social.microsoft.com/Forums/en-US/translator/thread/fa4063eb-3cf9-4b0b-872c-849623256d71

Meanwhile I am downloading the sources and will do it myself (set a global static variable just as the appid key, to be set when needed)

Regards.

[email protected]

Translate() returns an error message with text including double quotation.

This time, I stumble upon the error message below,

"There was an error deserializing the object of type System.String. Encountered unexpected character 'F'."

when I translate the text below,

"Mamma diceva sempre: devi gettare il passato dietro di te prima di andare avanti" Forrest Gump ragionava in maniera semplice, ma ci vedeva giusto.

I narrowed down the problem and found out that double quotation mark is a culprit. is it possible to work around the issue in the api?

Failed Hostname Verification Check

Hello,

I am receiving the following error:

java.lang.Exception: [microsoft-translator-api] Error retrieving translation : [Security:090504]Certificate chain received from datamarket.accesscontrol.windows.net - 70.37.92.127 failed hostname verification check. Certificate contained accesscontrol.windows.net but check expected datamarket.accesscontrol.windows.net

I have the following Code in my programs:

String client = "myclientid";
String secret = "myclientsecret";
Translate.setClientId(client);
Translate.setClientSecret(secret);

String transText = Translate.execute("hello", Language.ENGLISH, Language.FRENCH);
System.out.println(transText);

I have the appropriate imports in the code. I have also set up the account appropriately: I have subscribed to the Microsoft Translator API on Azure Marketplace and have registered my application in the Azure DataMarket.

Anyone have an idea how to fix this?

Thanks,
Nicole

Restart Token Expiration

Since Translate and MicrosoftTranslatorAPI are static classes, it would be convenient if there is a method that restarts the token expiration. This becomes useful when the Bing translation is used with multiple accounts, because I don't have to wait when trying to switch to different account. Of course, it would be better if MicrosoftTranslatorAPI does not have static methods at all, so it could be used with two or more accounts simultaneously.

Problem with access token

Hello,

I am trying to use library but it fails, I have created client Id and secret then I have used microsoft-translator-java-api library to translate.

The exception is:

java.lang.Exception: [microsoft-translator-api] Error retrieving translation : Server returned HTTP response code: 400 for URL: https://datamarket.accesscontrol.windows.net/v2/OAuth2-13
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:202)
at com.memetix.mst.translate.Translate.execute(Translate.java:61)
at Main.main(Main.java:89)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://datamarket.accesscontrol.windows.net/v2/OAuth2-13
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at com.memetix.mst.MicrosoftTranslatorAPI.getToken(MicrosoftTranslatorAPI.java:139)
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveResponse(MicrosoftTranslatorAPI.java:160)
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:199)
... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://datamarket.accesscontrol.windows.net/v2/OAuth2-13
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
at com.memetix.mst.MicrosoftTranslatorAPI.getToken(MicrosoftTranslatorAPI.java:138)
... 4 more

Can I help you?
Thanks in advance!

Two language names are misspelled in the Language enum

Haitian Creole and Ukrainian are misspelled.

Not sure if you'll want to fix it, leave it, or add correctly-spelled entries to maintain backward compatibility: One misspelling was carried over from the Google Translate Java API code.

Error retrieving translation : unable to parse 'null' as integer

i am just trying to run the bing translation java api v0.6 in android 2.3.3 performing an async task as here
https://github.com/rmtheis/android-ocr and getting the following error retrieving the translated text.

E/TranslatorBing(30659): Caught exeption in translation request.

W/System.err(30659): java.lang.Exception: [microsoft-translator-api] Error retrieving translation : unable to parse 'null' as integer

W/System.err(30659): at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:199)

W/System.err(30659): at com.memetix.mst.translate.Translate.execute(Translate.java:61)

W/System.err(30659): at edu.sfsu.cs.orange.ocr.language.TranslatorBing.translate(TranslatorBing.java:42)

W/System.err(30659): at edu.sfsu.cs.orange.ocr.language.Translator.translate(Translator.java:49)

W/System.err(30659): at edu.sfsu.cs.orange.ocr.language.TranslateAsyncTask.doInBackground(TranslateAsyncTask.java:58)

W/System.err(30659): at edu.sfsu.cs.orange.ocr.language.TranslateAsyncTask.doInBackground(TranslateAsyncTask.java:1)

W/System.err(30659): at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-21 16:58:38.085: W/System.err(30659): at

java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)

W/System.err(30659): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-21 16:58:38.085: W/System.err(30659): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)

W/System.err(30659): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)

W/System.err(30659): at java.lang.Thread.run(Thread.java:1019)

W/System.err(30659): Caused by: java.lang.NumberFormatException: unable to parse 'null' as integer

W/System.err(30659): at java.lang.Integer.parseInt(Integer.java:356)

W/System.err(30659): at java.lang.Integer.parseInt(Integer.java:332)

W/System.err(30659): at com.memetix.mst.MicrosoftTranslatorAPI.retrieveResponse(MicrosoftTranslatorAPI.java:158)

W/System.err(30659): at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:196)

W/System.err(30659): ... 11 more

TranslateAsyncTask(30659): FAILURE

Android Translate Error - App crashes

Hi,

I am running android 4.0 on a Motorola Xoom.
The app crashes on the line which sets the client id, and the one that sets the client secret.
I wondered if you could provide me with any ideas of common errors, or what I could check?
The client id and secret are correct, and the lines are:

Translate.setClientId("ID");
Translate.setClientSecret("SECRET");

Thanks!

Character encoding possibly wrong

I tried running this code:

String translatedText = Translate.execute("Bonjour le monde", Language.FRENCH, Language.CHINESE_SIMPLIFIED);
System.out.println("French -> Chinese T : " + translatedText);

It printed out

French -> Chinese T : ????

It looks like you're not using UTF8.

SpokenDialect.ENGLISH_UNITED_KINGDOM is broken

Incorrect language code in constant. Long-term, should probably consider just loading all language stuff dynamically from the available services

code is currently "en-uk" in 0.3

need to make it "en-gb"

Credential error but still returns Http response code 200

If I use the wrong credential to connect to MS translator service, the Http connection will return a 200 OK code, but the returned string contains the error:

"TranslateApiException: Cannot find an active Azure Market Place Translator Subscription associated with the request credentials...."

So the Exception is no longer thrown (because the returned code is 200). Instead the error message becomes the translated text returned.

Rethink Language Enum Pattern

Language Enum pattern requires recompilation to support new Languages.

Design a better / new way to support a live list of Languages supported by the Translator API.

Bulk Translation causes crash: Cant cast String to JsonArray

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.]

getToken() not working on Android

There seems to be a problem with the POST in getToken() not returning a result when running on Android.

I tested it on Android 4.0.2. When I replaced the method with a new one using Apache Commons' HttpClient instead of HttpURLConnection, the method worked. HttpURLConnection is the recommended HTTP client on Android 2.3.x, though. [1]

Sorry for the lack of detail on this--I plan to take a closer look when I have a chance.

[1] http://android-developers.blogspot.com/2011/09/androids-http-clients.html

Request limit for translation differs for Chinese

From email report:

For English, German, Latvian, Estonian, Slovenian, Romanian, Lithuanian, the text length limitation for each translation call is 10240. However, for Chinese, it is about 2000, and for Greek it is about 3000. You can test it with my attached examples. Is it because Greek and Chinese are quite different to the Western languages? For example, they might use other language encoding system, and a character takes 2 bytes?

Java Versioning issue

Via email:

Hi Jonathan,

My name is Alex. I'm writing to you in order to make a contribution on microsoft-translator-java-api project.
I'm running Linux box and microsoft-translator-java-api has a compilation problem under Linux.
Since you didn't specify the version of java in pom file it's going to use 1.3 which is incompatible with the source code as it was done using 1.6 I guess.
So my fix is to add few lines into the pom file to specify the version of java to use.
I've attached diff file which you can use to import the changes to your project. Also you can add me as a contributor so I can commit those changes as well.

Here are those lines I've added to pom.xml:

<!-- Configure Compiler -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>

Here is compilation error I had:
$ mvn clean install -Dmaven.skip.test=true
[INFO] Compiling 7 source files to /home/user/documents/prj/opensource/microsoft-translator-java-api/target/classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure

/home/user/documents/prj/opensource/microsoft-translator-java-api/src/main/java/com/memetix/mst/translate/Translate.java:[126,24] for-each loops are not supported in -source 1.3
(use -source 5 or higher to enable for-each loops)
        for(String text : texts) {

And here is my software installed:
# mvn -v
Apache Maven 2.2.1 (rdebian-8)
Java version: 1.6.0_26
Java home: /usr/lib/jvm/java-6-sun-1.6.0.26/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-5-686" arch: "i386" Family: "unix"

Please let me know if those changes are OK and when it will be deployed to maven repo.

Thanks,
-- Alex

Provide a way to specify TO/FROM languages using String instead of Language Enum

Need to provide a way to use the API without having to use the Language Enum. Preferably, user should be able to pass in a String representing the Microsoft Translator Language code.

This would allow the Java API to support new languages as the Microsoft service adds support, without the need to release new code (i.e., a new instance of the Language Enum).

Translate.execute(text,to) returns null when passed some particular text.

it always returns null when I pass the Japanese sentence shown below to execute() method with the target language as Language.ENGLISH. any idea how to solve this?

Nobuko Katoさんは土佐の出来人【長宗我部元親】タイプです。
大器晩成の四国の雄。姫若子と揶揄された中、初陣で大活躍、大転身で四国統一!実力あれどメンタルの弱さが欠点かも?
あなたが戦国武将なら誰タイプ?判定してみよう!
http://www.facebook.com/pages/戦国武将判定/276373512417331?sk=app_109770245765922
[スマートフォンの方はこちら]
http://apps.facebook.com/busho_judge/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.