内容简介:由于excite关闭了网页翻译功能,google的网页翻译有时候也不太灵光,就去看了下jbeijing的翻译API调用,正好VNR中已有相关代码,就学习一下。这段代码是调用JBJCT.dll中的方法(看注释大神是用IDA反编译dll在看函数的参数),功能是将unicode文本从日文翻译成中文,下面是运行效果
由于excite关闭了网页翻译功能,google的网页翻译有时候也不太灵光,就去看了下jbeijing的翻译API调用,正好VNR中已有相关代码,就学习一下。
def transferUnicode(self, text, to, fr=CODEPAGE_JA):
"""
@param text unicode not str
@param to uint code page
@param fr uint code page
@raise WindowsError, AttributeError
From IDA:
int __cdecl JC_Transfer_Unicode(int, UINT CodePage, int, int, int, LPCWSTR lpWideCharStr, int, int, int, int)
Values are get by runtime debugging.
Guessed
int __cdecl JC_Transfer_Unicode(
HWND hwnd,
UINT fromCodePage,
UINT toCodePage,
int unknown,
int unknown,
LPCWSTR from,
LPWSTR to,
int &toCapacity,
LPWSTR buffer,
int &bufferCapacity)
Note: This function is not thread-safe!
Using persistent buffers is faster, but not thread-safe!
"""
size = BUFFER_SIZE
if self.BUFFER_THREAD_SAFE:
# Limit buffer size would result in crash ... no idea why
#size = min(size, len(text) * 10) # the translation should be no more larger than 10 times of Japanese
out = ctypes.create_unicode_buffer(size)
buf = ctypes.create_unicode_buffer(size)
else:
out = self.buffer1
buf = self.buffer2
outsz = ctypes.c_int(size)
bufsz = ctypes.c_int(size)
#self.dll.JC_Transfer_Unicode(
self.JC_Transfer_Unicode(
0, # int, unknown
fr, # uint from, supposed to be 0x3a4 (cp932)
to, # uint to, eighter cp950 or cp932
1, # int, unknown
1, # int, unknown
text,
out, # wchar_t*
ctypes.byref(outsz), # ∫
buf, # wchar_t*
ctypes.byref(bufsz)) # ∫
return out.value
这段代码是调用JBJCT.dll中的方法(看注释大神是用IDA反编译dll在看函数的参数),功能是将unicode文本从日文翻译成中文,下面是运行效果
结果
实际运用中发现一个问题,翻译的文本是有上限的,如果原文是太长的文章,返回的译文可能会缺失(大概5k以上不行)
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- golang调用baidu翻译api实现自动翻译
- 基于 Laravel、Lumen 框架集成百度翻译、有道翻译、Google 翻译扩展包
- 腾讯发布人工智能辅助翻译 致敬人工翻译
- 监管机器翻译质量?且看阿里如何搭建翻译质量评估模型
- 机器翻译新突破:谷歌实现完全基于attention的翻译架构
- PendingIntent 是个啥?官方文档描述的很到位。我给翻译翻译
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Data Structures and Algorithms in Java
Michael T. Goodrich、Roberto Tamassia / Wiley / 2010-01-26 / USD 177.41
* This newest edition examines fundamental data structures by following a consistent object-oriented framework that builds intuition and analysis skills of data structures and algorithms * Presents ne......一起来看看 《Data Structures and Algorithms in Java》 这本书的介绍吧!