Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate file with Google Translator Java API

I´m using this code:

GttService myService = new GttService("ex1cor.ex1Ap.1");
myService.setUserCredentials("[email protected]", "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 TargetLanguage(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!

like image 590
lena Avatar asked May 28 '26 15:05

lena


1 Answers

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.

like image 162
lisak Avatar answered Jun 03 '26 01:06

lisak