Search code examples
javamicrosoft-translator

issue with Microsoft translator java api


I was searching around for a free translation API for Java, I found microsoft-translator-java-api, it is very easy to use I liked that, but when I translate from English to Arabic like :

public static void main( String[] args ) throws Exception {       

    // Set the Client ID / Client Secret once per JVM. It is set statically and applies to all services
    Translate.setClientId("MY_CLIENT_ID_KEY");
    Translate.setClientSecret("MY_CLIENT_SECRET_KEY");

    // From English-> Arabic
    String translatedText = Translate.execute("When creating a text field component, it’s common to specify some initial text and/or a number of columns from which the field’s width is calculated.", Language.ENGLISH, Language.ARABIC);

    System.out.println(" English -> Arabic: " + translatedText);

}

I get out put on console as :

 English -> Arabic : ??? ????? ???? ??? ??? ?????? ?????? ??? ???? ??????? ?/?? ??? ?? ??????? ???? ?? ?????? ??? ???? ????? ?????.

I m confused how to get this bug fixed so that I can get Some meaning full characters on the console instead of that above.


Solution

  • You have to change the encoding of the console to UTF-8 then the Arabic characters will be correctly displayed.
    If you are using eclipse do the steps below:

    Step 1:

    Click Run --> Run Configurations..

    enter image description here

    Step 2:

    Click on the Common tab -> select Other -> Change encoding to UTF-8

    enter image description here

    Step 3:

    Click apply and the Arabic text can now be printed on the console.