使用 Google Translator Java API 翻译文件

发布于 2024-09-18 05:34:22 字数 1156 浏览 2 评论 0原文

我正在使用这段代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼波传意 2024-09-25 05:34:22

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文