Skip to content

marmot-z/bing-translate-api-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Java toolkit for invoking Bing Translator to translate text, ported from the bing-translate-api project.

Usage

Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("localhost", 1080));
OkHttpClient httpClient = new OkHttpClient().newBuilder()
      // use http proxy
      .proxy(proxy)
      .build();
BingTranslator translator = new BingTranslator(httpClient);

try {
   TranslationParams params = TranslationParams.builder()
         .text("你好")
         .fromLang("auto-detect")
         .toLang("en")
         .build();
   TranslationResult result = translator.translate(params);
   
   System.out.println(result);
}
// the following exception thrown when an error occurs
// in translate (or getting translation config)
catch (TranslateException | TranslationConfigLoadException e) {
    e.printStackTrace();
} finally {
    translator.close();
}

Features

  • Supports multithreading
  • Automatic refresh of translation configuration

FAQs & Solutions

  • If the response code is 401, it means the request frequency is too high, and you need to use captcha verification. In this case, you should reduce the request frequency appropriately.
  • If the response content is {"ShowCaptcha": true}, it means the request frequency is too high, and you need to use captcha verification. In this case, you should reduce the request frequency appropriately.

Additionally, using a proxy pool is a better solution.

About

A simple and free API for Bing Translator for Java

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages