Microsoft

API - Translator Text: Java- Using SSL with the Microsoft Translator API

Here is the working code with HTTPS.

private static final String httpsTranslateURLTemplate = "https://api.microsofttranslator.com/V2/Ajax.svc/Translate?from=%1s&to=%2s&appid=%3s&text=%4s";
     
public static void main(String[] args) {
            AdmAccessToken accessToken = AdmAccessToken.getAccessToken("ClientID", "ClientSecret");
           
            String translatedText = Translate(accessToken.access_token, "en", "fr", "today is sunday");
            System.out.printf("Translated Text: "+ translatedText);
}


private static String Translate(String accessToken, String from, String to, String text) {
            try {
                  String accessTokenToSend = UrlEncoded.encodeString("Bearer " + accessToken, StandardCharsets.UTF_8);
                  String textToSend = UrlEncoded.encodeString(text, StandardCharsets.UTF_8);
                  URL translateUrl = new URL(String.format(httpsTranslateURLTemplate, from, to, accessTokenToSend, textToSend));
                  HttpsURLConnection connection = (HttpsURLConnection) translateUrl.openConnection();
                  connection.getResponseCode();
                  try (BufferedReader reader = new BufferedReader(new InputStreamReader(translateUrl.openStream(), StandardCharsets.UTF_8))) {
                        StringBuffer res = new StringBuffer();
                        String line;
                        while ((line = reader.readLine()) != null) {
                              res.append(line);
                        }
                        return res.toString();
                  }

            } catch (Exception e) {
                  e.printStackTrace();
            }
            return null;
      }

Translator

  1. Announcement: Changes to the Collaborative Translation functions
  2. Translator Hub replaces the Collaborative Translation Framework (CTF)
  3. Microsoft Translator Moves to the Azure portal
  4. API - Translator datacenters
  5. API and Hub: Confidentiality
  6. API - Translator Speech: Microsoft Translator Speech API references
  7. API - Translator Text: How to report an issue with the API
  8. API - Translator Text / Speech: Microsoft Translator with IP filtered firewalls
  9. API - Translator Text / Speech: Get a report of your consumption
  10. API - Translator Text / Speech: Using the API key directly in the call. No more token.
  11. API - Translator Text / Speech: Why are there two keys for my API subscription?
  12. API - Translator Text: Hybrid Neural Machine Translation
  13. API - Translator Text: Using Neural MT Systems
  14. API- Translator Text: Standard category languages
  15. API - Translator Text: My CAT tool isn't working and is asking for the Client ID and Client Secret
  16. API - Translator Text: Limits
  17. API - Translator Text: How Microsoft Translator counts characters
  18. API - Translator Text: Gender selection in the Speak() method
  19. API - Translator Text: Trados plugin for Microsoft Translator
  20. API - Translator Text: Java- Using SSL with the Microsoft Translator API
  21. API - Translator Text: European datacenter
  22. API - Translator Text: Languages detected by the Detect() method
  23. API - Translator Text: First few Microsoft Translator API requests succeed, then the calls fail
  24. API - Translator Text: Profanity filtering in the TranslateArray() method
  25. API - Translator Speech: Signal the end of the utterance
  26. Hub: API available
  27. Hub: Translator Hub Resource Guide
  28. Hub: August 2016 Release notes
  29. Hub: Deployment of a custom system requires a Microsoft Translator Text API subscription in the Azure portal
  30. Hub: Capacity of custom Microsoft Translator Hub systems
  31. Hub: Building a custom system using a dictionary only
  32. Business Applications: Security and Privacy in Microsoft Office Products

Feedback and Knowledge Base