2010-09-02 158 views
2

I'm:翻譯文件,使用此代碼谷歌翻譯的Java API

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); 

什麼也沒發生。沒有錯誤...只是沒有!

回答

1

Google譯者工具包API不提供文件翻譯服務。目前它只提供文件管理。如果你想翻譯一些東西,你可能想看看this。它工作得很好,但它有一些缺陷。例如,文檔的最大限制爲5000個字符。這個API並不關心它,因爲它不是主要用於文檔翻譯,而是用於翻譯許多小文本。