Methods
(async) sleep(delay) → {Promise.<void>}
自定义的辅助 sleep() 函数,用于阻断主线程,防止访问服务器的频率过高
Parameters:
Name | Type | Description |
---|---|---|
delay |
number | 要停滞的毫秒数 |
- Source:
Returns:
- Type
- Promise.<void>
(async) translateFile(sourceFilePath, fromopt, toopt, typeopt) → {Promise.<void>}
翻译全文,保存成一个新的文件
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sourceFilePath |
string | 待翻译的文件路径 | ||
from |
string |
<optional> |
en | 源语言 |
to |
string |
<optional> |
zh | 目标语言 |
type |
string |
<optional> |
auto | 输出文件的类型 |
- Source:
Returns:
- Type
- Promise.<void>
(async) translateResults(src, fromopt, toopt) → {Promise.<Array>}
返回只包含目标语言的翻译结果数组
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
src |
string | 待翻译的字符串,多个查询用 \n 隔开 | ||
from |
string |
<optional> |
en | 源语言 |
to |
string |
<optional> |
zh | 目标语言 |
- Source:
Returns:
- Type
- Promise.<Array>
(async) translateServerResponse(query, fromopt, toopt) → {Promise.<object>}
向百度翻译服务器发送请求的最基本函数,返回一个包含很多信息的对象
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
query |
string | 待翻译的字符串,多个查询用 \n 隔开 | ||
from |
string |
<optional> |
en | 源语言 |
to |
string |
<optional> |
zh | 目标语言 |
- Source:
Returns:
- Type
- Promise.<object>