开发者

Translate file with Google Translator Java API

开发者 https://www.devze.com 2023-01-14 21:03 出处:网络
I´m using this code: GttService myService = new GttService(\"ex1cor.ex1Ap.1\"); myService.setUserCredentials(\"example@gmail.com\", \"password\");

I´m using this code:

GttService myService = new GttService("ex1cor.ex1Ap.1");
myService.setUserCredentials("example@gmail.com", "password");

DocumentEntry entry = new DocumentEntry();

// Set source language
String srcLang = "en";
entry.setSourceLanguage(new SourceLanguage(srcLang));

// Set target language
String targetLang = "ja";
entry.setTargetLanguage(new TargetLangua开发者_如何学运维ge(targetLang));

// Set title
String title = "Test";
entry.setTitle(new PlainTextConstruct(title));

// Set local file for upload.
String filename = "D:\\translate\\english.txt";
File file = new File(filename);
String mimeType = "text/plain";

MediaFileSource fileSource = new MediaFileSource(file, mimeType);
MediaContent content = new MediaContent();
content.setMediaSource(fileSource);
content.setMimeType(new ContentType(mimeType));
entry.setContent(content);

URL feedUrl = new URL("http://translate.google.com/toolkit/feeds/documents");

DocumentEntry resultEntry = myService.insert(feedUrl, entry);

Nothing happened. No errors... just nothing!


Google Translator Toolkit API doesn't offer document translation services. It offers only document management for now. If you want to get something translated, you might want to look at this. It works very well, but it has some flaws. For instance there is a limit of 5000 characters for a document. This API doesn't take care of it because it is not primarily supposed for document translation, but rather for translation of many little pieces of text.

0

精彩评论

暂无评论...
验证码 换一张
取 消