使用 Google Translator 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);
什么也没发生。没有错误...只是什么都没有!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Google Translator Toolkit API 不提供文档翻译服务。目前它仅提供文档管理。如果您想要翻译某些内容,您可能需要查看此 。它工作得很好,但也有一些缺陷。例如,文档的字符数限制为 5000 个字符。这个 API 不关心它,因为它主要不是用于文档翻译,而是用于翻译许多小文本片段。
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.